C++ GUI write to textBox while using backgroundWorker - user-interface

I am trying to write to a textBox while having a loop on backgroundworker. I tried using Invoke/BeginInvoke however I couldn't do it. How can I change it to make it work? Here is my code below, thanks in advance.
delegate void backgroundWorker1_DoWorkDelegate(Object^ sender, DoWorkEventArgs^ e);
private: System::Void backgroundWorker1_DoWork(System::Object^ sender, System::ComponentModel::DoWorkEventArgs^ e) {
if (textBox1->InvokeRequired)
{
backgroundWorker1_DoWorkDelegate^ action = gcnew backgroundWorker1_DoWorkDelegate(this, &MyForm::Worker);
this->BeginInvoke(action);
}
else
{
textBox1->Text = "a";
} ... }
void Worker(System::Object^ sender, System::ComponentModel::DoWorkEventArgs^ e)
{
textBox1->Text = "a";
}

Related

How to use SOAP in windows phone 7

Dont know what to do.
I have all the data i need but dont know how to use it right.
I have started to add a "Service Reference". I added the URL wich is this one: transpawebserviceslive/gateway.asmx
So what i have done now is this. For my click event on my button to verify that the password and username is correct i have done the following and i dont know if i am doing it right here:
private void Button_Click_1(object sender, RoutedEventArgs e)
{
ServiceReference.GatewaySoapClient client = new ServiceReference.GatewaySoapClient();
client.AuthenticateAsync(username.Text,password.Text,sign.Text,password.Text);
client.AuthenticateCompleted += client_AuthenticateCompleted;
}
void client_AuthenticateCompleted(object sender, ServiceReference.AuthenticateCompletedEventArgs e)
{
ServiceReference.AuthenticatedDto test = new ServiceReference.AuthenticatedDto();
if (kund.Text == test.CustomerUser)
{
MessageBoxResult m = MessageBox.Show("Ok", "Ok", MessageBoxButton.OK);
}
else
{
MessageBoxResult m = MessageBox.Show("Wrong", "W", MessageBoxButton.OK);
}
Dont know what i am doing here, whould be nice with some help.
All that you did there is correct. You just have to parse the response and proceed.
void client_AuthenticateCompleted(object sender, ServiceReference.AuthenticateCompletedEventArgs e)
{
if (e.Error == null) //To ensure there is no error in the request
{
if (e.Result.Contains("ERROR"))
MessageBox.Show("Authentication failed", "Ok", MessageBoxButton.OK);
else
MessageBox.Show("Authenticaion success", "Ok", MessageBoxButton.OK);
}
}

PositionChanged & StatusChanged event getting fired twice in WP7

I am trying to getting coordinates with the help of GPS and when i am putting a dry run or debug the event makes PositionChange & StatusChange to call TWICE. Here is my code please help me.
private void button1_Click(object sender, RoutedEventArgs e)
{
if (NetworkInterface.GetIsNetworkAvailable())
{
flag = true;
if (watcher == null)
{
watcher = new GeoCoordinateWatcher(GeoPositionAccuracy.Default);
watcher.MovementThreshold = 20;
watcher.PositionChanged += new EventHandler<GeoPositionChangedEventArgs<GeoCoordinate>>(watcher_PositionChanged);
watcher.StatusChanged += new EventHandler<GeoPositionStatusChangedEventArgs>(watcher_StatusChanged);
watcher.Start();
}
}
}
void watcher_StatusChanged(object sender, GeoPositionStatusChangedEventArgs e)
{
switch (e.Status)
{
case GeoPositionStatus.Disabled:
MessageBox.Show("Location Service is not enabled on the device");
break;
case GeoPositionStatus.NoData:
MessageBox.Show(" The Location Service is working, but it cannot get location data.");
break;
}
}
void watcher_PositionChanged(object sender, GeoPositionChangedEventArgs<GeoCoordinate> e)
{
if (e.Position.Location.IsUnknown)
{
MessageBox.Show("Please wait while your prosition is determined....");
return;
}
List<string> locationData = new List<string>();
locationData.Add(e.Position.Location.Latitude.ToString("Latitude:" + "0.000"));
locationData.Add(e.Position.Location.Longitude.ToString("Longitude:" + "0.000"));
locationData.Add(e.Position.Location.Altitude.ToString());
locationData.Add(e.Position.Location.Speed.ToString());
locationData.Add(e.Position.Location.Course.ToString());
}
It's called twice because the status changes from
Initializing -> Ready
For Initializing it fires once and For ready the second time :)

Where to access the isolated storage value?

public IsolatedStorageSettings appSettings =
IsolatedStorageSettings.ApplicationSettings;
public Settings()
{
InitializeComponent();
this.toggle.Checked += new EventHandler<RoutedEventArgs>(toggle_Checked);
this.toggle.Unchecked += new EventHandler<RoutedEventArgs>(toggle_Unchecked);
this.toggle.Click += new EventHandler<RoutedEventArgs>(toggle_Click);
this.toggle.Indeterminate += new EventHandler<RoutedEventArgs>(toggle_Indeterminate);
`}`
void toggle_Unchecked(object sender, RoutedEventArgs e)
{
this.toggle.Content = "Visibity is off";
this.toggle.SwitchForeground = new SolidColorBrush(Colors.Red);
appSettings.Add("value", "off");
}
void toggle_Checked(object sender, RoutedEventArgs e)
{
this.toggle.Content = "Visibity is on";
this.toggle.SwitchForeground = new SolidColorBrush(Colors.Green);
appSettings.Add("value", "on");
}
void toggle_Indeterminate(object sender, RoutedEventArgs e)
{
//add some content here
}
void toggle_Click(object sender, RoutedEventArgs e)
{
//add some content here
}
by default calling checked method.If a user unchcked the button then again an user logged in app need to show the unchcked because the user previously unchcked the btn.but it's show checked.for that i am saving one value in isolated storage.
can you please tell me where to access the isolated varieable value ?
You can access the isolatedstorage value in any page, in the same way as you created it.
Try to access the value in Settings() constructor after the InitializeComponent();
public Settings()
{
InitializeComponent();
string value;
if (appSettings.Contains("value"))
{
appSettings.TryGetValue("value", out value);
}
and then you can change the value of toggle button based on the 'value'.
It seems that you are not calling the Save method on the ApplicationSettings object.
Please read this guide on how you should work with isolated storage.
To save a setting:
IsolatedStorageSettings settings = IsolatedStorageSettings.ApplicationSettings;
if (!settings.Contains("userData"))
{
settings.Add("userData", "some value");
}
else
{
settings["userData"] = "some value";
}
settings.Save();
To retrieve a setting:
if (IsolatedStorageSettings.ApplicationSettings.Contains("userData"))
{
string result IsolatedStorageSettings.ApplicationSettings["userData"] as string;
}
So in your case, save the state of the CheckBox in the Checked & UnChecked event, and load the state in the init of the page.

PostBack and session values. Why after button is clicked and session created postback still show null

protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
lblPostBack.Text = " Text created first time";
}
else
{
if (Session["Counter"] == null)
{
lblPostBack.Text = "PostBack x however strange becasue if is postback it's mean somebody clicked button and session value has been created";
}
else
{
lblPostBack.Text = "PostBack x should be count here";
}
}
}
protected void cmd_Click(object sender, EventArgs e)
{
int _counter;
if (Session["Counter"] == null)
{
_counter = 1;
}
else
{
_counter = (int)Session["Counter"] + 1;
}
Session["Counter"] = _counter;
lblPostBack.Text += "Counter: " + _counter.ToString();
}
Assuming this is ASP.NET: It's because the Click event on your button fires after the Load event on your page, so the session has not been set.
MSDN on the page lifecycle might be good reading - the button click is a "postback event" in the table in that document.
If I've got the wrong end of the stick, please explain what messages you get after the button clicks, and what you were expecting. Some framework and language tags on the question might not go amiss, either.
Ok it works, just FF mess up
I have added following method and works fine.
private int _counter;
protected void Page_Load(object sender, EventArgs e)
{
(...)
protected void Page_PreRender(Object sender, EventArgs e)
{
Session["Counter"] = _counter;
}

Difficulty with GridView PostBack Events

In the RowDataBound OnClick event handler, its printing 'Hi' when I click on any row. But I want it to only print 'Hi' when I click on the 15th row. How can I implement this?
My code:
protected void dtvExDetails_RowDataBound1(object sender, GridViewRowEventArgs e)
{
if (e.Row.DataItemIndex == -1)
return;
e.Row.Attributes.Add("onMouseOver","this.style.cursor='hand';");
e.Row.Attributes.Add("onclick", this.GetPostBackClientEvent(dtvExDetails, "Select$15"));
}
protected void dtvExDetails_SelectedIndexChanged(object sender, EventArgs e)
{
Response.Write("hi");
DataGrid();
}
protected void dtvExDetails_SelectedIndexChanged(object sender, EventArgs e)
{
GridViewRow selrow = sender as GridViewRow;
if(selrow.Count == 15)
Response.Write("hi");
DataGrid();
}

Resources