Re: Telling the user what's happening
- From: "<ctacke/>" <ctacke[@]opennetcf[dot]com>
- Date: Sat, 6 Jan 2007 08:01:13 -0500
I can't explain the GWES crash, but your thread.Join call stops message
handling just like you were doing before, so it should give the same
behavior as before. The point Paul was making is that the main thread,
which is where the mesage pump is, must _continue_ to run.
If you want the worker thread to communicate back status info or
completeion, it should use Control.Invoke.
--
Chris Tacke
OpenNETCF Consulting
Managed Code in the Embedded World
www.opennetcf.com
--
"Joel Finkel" <JoelFinkel@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:F7A1C6A8-E9CF-4032-84AB-D1F117B5B183@xxxxxxxxxxxxxxxx
Paul,
Thanks, but the following code fails. Not only is no Notification
displayed
(there IS a beep), but I consistently get a crash in gwes.exe. Here is
the
code:
In the Form class:
private void button1_Click(object sender, EventArgs e)
{
using (Notification myNotification = new Notification())
{
myNotification.Text = "Please wait while we do some stuff";
myNotification.Caption = "Processing...";
myNotification.InitialDuration = 10;
myNotification.Critical = false;
myNotification.Visible = true;
ThreadStart threadDelegate = new ThreadStart(Work.DoWork);
Thread newThread = new Thread(threadDelegate);
newThread.IsBackground = true;
newThread.Start();
// Blocks the calling thread until a thread terminates, while
continuing
// to perform standard COM and SendMessage pumping.
//
// Note that the code fails even if we do not Join the newThread.
newThread.Join();
}
// The rWork.results are displayed, there is an immediate crash in
// gwes.exe, and the MessageBox displays until it is closed by the user.
MessageBox.Show(Work.results);
}
// a Work class
class Work
{
public static string results;
public static void DoWork()
{
// pretend to do some work
Thread.Sleep(4000);
results = "Hello sailor";
}
}
"Paul G. Tobey [eMVP]" wrote:
I'm sure that the notification is using the message loop to process
messages. If you halt the message loop while you do the processing,
nothing
happens. Create the notification, fork a thread to do the processing,
and
continue with the message loop in the main thread. When the worker
thread
is done, have it notify the UI thread somehow that it's done and have
that
thread, in turn, take down the notification.
Paul T.
"Joel Finkel" <JoelFinkel@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:3F04CCCF-9F81-419A-B0A8-B6742FF2715D@xxxxxxxxxxxxxxxx
More information:
At the end of the processing, I am showing a MessageBox. When this is
displayed, the Notification window also appears.
If I comment that out, so that no MessageBox is displayed at the end of
the
processing steps, the system throws an error that results in a "We're
Sorry"
form that indicates that "A problem has occurred with gwes.exe" and
asks
the
user to send the information to Microsoft.
This happens both with an emulator and an actual device.
/Joel
"Amit" wrote:
Hi
Code looks okey.Try to put the notification code in a seprate function
call
and see what happens.
Alternative you can also try Progress bar control.
--
Thanks and Regards
Amit Ranjan
blog:http://amitranjan.wordpress.com
"Joel Finkel" wrote:
Folks,
On a Windows Mobile 5.0 device, what is the canonical method for
displaying
a status window that informs the user that something is going on in
the
background. I tried using Notification, but it only appeared after
the
processing was done:
using (Notification note = new Notification() {
note.Text = "Something is happening.";
note.InitialDuration = 10;
note.visible = true;
// do some processing
// ...
// the Notification window gets displayed now, not at the
beginning
}
.
- Follow-Ups:
- Re: Telling the user what's happening
- From: Joel Finkel
- Re: Telling the user what's happening
- References:
- Re: Telling the user what's happening
- From: Paul G. Tobey [eMVP]
- Re: Telling the user what's happening
- From: Joel Finkel
- Re: Telling the user what's happening
- Prev by Date: Re: Telling the user what's happening
- Next by Date: Re: Telling the user what's happening
- Previous by thread: Re: Telling the user what's happening
- Next by thread: Re: Telling the user what's happening
- Index(es):