Hi,

I am a beginner learning how to develop application for smart device. I want
my application to verify network connection when application startup. When
verifying network connection, I display status using ProgressBar. I
understand that I will need to run the verify network procedure on a new
thread so that the Form interface can completely load.

Below is my code snippet:

private Thread threadVerifyConnection;

public FormMain()
{
InitializeComponent();
threadVerifyConnection = new Thread(new
ThreadStart(this.VerifyConnection));
threadVerifyConnection.Start();
}

private void VerifyConnection()
{
WebRequest webRequest = WebRequest.Create("UrlString");
webRequest.Timeout = 5000;
IAsyncResult result = webRequest.BeginGetResponse(null, null);

while (!result.IsCompleted)
{
if (progressBarConnection.Value == progressBarConnection.Maximum)
progressBarConnection.Value = 0;
else
progressBarConnection.Value = progressBarConnection.Value + 1;

progressBarConnection.Update();
}

HttpWebResponse response = (HttpWebResponse)
webRequest.EndGetResponse(result);

//... do something here
}

But I think I must be understand something wrongly as when I run my
application onto the Pocket PC 2002 Emulator, nothing come out... not even
the Form!! But I can see from the emulator's memory that the application is
running but not responding.

Can someone enlighten me?

Thank you.

--
Soul

RE: Verify Connetion when Form Loaded by jaison_n_john

jaison_n_john
Sun May 16 13:16:02 CDT 2004

Hello Soul

There is nothing intuitively wrong with your code. However, try creating and starting the verifying thread from the form's Load event or the OnLoad method instead of within the constructor.

All the best1

Re: Verify Connetion when Form Loaded by Andy

Andy
Sun May 16 21:24:03 CDT 2004

Read this article.
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnforms/html/winforms06112002.asp

Updating the UI from a thread other than UIs creating thread is a no-no.

"Soul" <no@spam.net> wrote in message
news:%23IxJ1X0OEHA.3096@TK2MSFTNGP09.phx.gbl...
> Hi,
>
> I am a beginner learning how to develop application for smart device. I
want
> my application to verify network connection when application startup. When
> verifying network connection, I display status using ProgressBar. I
> understand that I will need to run the verify network procedure on a new
> thread so that the Form interface can completely load.
>
> Below is my code snippet:
>
> private Thread threadVerifyConnection;
>
> public FormMain()
> {
> InitializeComponent();
> threadVerifyConnection = new Thread(new
> ThreadStart(this.VerifyConnection));
> threadVerifyConnection.Start();
> }
>
> private void VerifyConnection()
> {
> WebRequest webRequest = WebRequest.Create("UrlString");
> webRequest.Timeout = 5000;
> IAsyncResult result = webRequest.BeginGetResponse(null, null);
>
> while (!result.IsCompleted)
> {
> if (progressBarConnection.Value == progressBarConnection.Maximum)
> progressBarConnection.Value = 0;
> else
> progressBarConnection.Value = progressBarConnection.Value + 1;
>
> progressBarConnection.Update();
> }
>
> HttpWebResponse response = (HttpWebResponse)
> webRequest.EndGetResponse(result);
>
> //... do something here
> }
>
> But I think I must be understand something wrongly as when I run my
> application onto the Pocket PC 2002 Emulator, nothing come out... not even
> the Form!! But I can see from the emulator's memory that the application
is
> running but not responding.
>
> Can someone enlighten me?
>
> Thank you.
>
> --
> Soul
>
>
>
>