Hello guys!
I have an app which is checking an internet page for its content. And my app is checking this page every 2 minutes.
Now, I created a thread to do this...but the problem is that the app is freezing for a second(or a few seconds) when my thread starts running. So I can't move the form..or anything else.
This is my thread:
Can you tell me please what is the best way to deal with this?
Thank you.
I have an app which is checking an internet page for its content. And my app is checking this page every 2 minutes.
Now, I created a thread to do this...but the problem is that the app is freezing for a second(or a few seconds) when my thread starts running. So I can't move the form..or anything else.
This is my thread:
VB.NET:
[SIZE=2][COLOR=#0000ff]Private[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Sub[/COLOR][/SIZE][SIZE=2] timerMsg_Tick([/SIZE][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][SIZE=2] sender [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Object[/COLOR][/SIZE][SIZE=2], [/SIZE][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][SIZE=2] e [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] System.EventArgs) [/SIZE][SIZE=2][COLOR=#0000ff]Handles[/COLOR][/SIZE][SIZE=2] timerMsg.Tick[/SIZE]
[SIZE=2][COLOR=#0000ff]Try[/COLOR][/SIZE]
[SIZE=2]Console.WriteLine([/SIZE][SIZE=2][COLOR=#800000]"Checking for messages..."[/COLOR][/SIZE][SIZE=2] + Now)[/SIZE]
[SIZE=2]thMsg = [/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] System.Threading.Thread([/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] System.Threading.ThreadStart([/SIZE][SIZE=2][COLOR=#0000ff]AddressOf[/COLOR][/SIZE][SIZE=2] checkForMessages))[/SIZE]
[SIZE=2]thMsg.Start()[/SIZE]
[SIZE=2][COLOR=#0000ff]Catch[/COLOR][/SIZE][SIZE=2] err [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] Exception[/SIZE]
[SIZE=2]MessageBox.Show([/SIZE][SIZE=2][COLOR=#800000]"timerMsg error: "[/COLOR][/SIZE][SIZE=2] + err.Message)[/SIZE]
[SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Try[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Sub[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]Private[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Sub[/COLOR][/SIZE][SIZE=2][COLOR=#000000] checkForMessages()[/COLOR][/SIZE]
[COLOR=#000000]'code in here[/COLOR]
[SIZE=2][COLOR=#000000][SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Sub[/COLOR][/SIZE]
[/COLOR][/SIZE][/COLOR][/SIZE]
Thank you.