Jump to content

How to use ExitThread ?


Guest ChinDangShun

Recommended Posts

Guest ChinDangShun

I'm having a Mio 8390 running on MS Mobile 2003 for Smartphone. I try to develop a simple program with VS 2003.Net in which the app will print out continuously a string from 0 to 255 to the screen. The code is inside a For..Next loop.

I design the soft menu in the left a code that will end the entire application while the above For..Next is running (Force to end the application).

The code I use is: Application.Exit()

When I click this menu while For..Next is running, the Emulator stops the program and return to home screen but VS.Net 2003 does not stop. It raised an error that the For..Next still runs and it dose not stop debuging.

Then, I used Form.Close() method. The result is still above

Then, I open help and found the ExitThread method for Application but when I write Application, there are only methods: DoEvents, Exit, Run.

So, how to solve the problem ? and where the Application.ExitThread locate ?

Thank you !

Link to comment
Share on other sites

Hi.

I am not so familar with .NET but even more with traditional C++.

Your problem seems to be that the for..loop runs in the main thread of the program and therefore uses all processing time dedicated to this thread.

The windows message to show the menu is not processed in the eventhandler while in the for..loop.

That means windows sends the command to open the menu or shutdown the app but your app never receives this message.

There are 2 possible solutions to this problem:

1. Write a seperate Thread in which the for..loop runs. if you want to exit the program you can terminate the thread and then your program.

2. This should be quite easy: Add line inside your loop code in which you process the message queue. Don't know which command you have to use in .NET

Hope this helps a little bit

Link to comment
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.