Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

handling threads in .net compact framework..

Posted on 2004-11-04
4
Medium Priority
?
1,136 Views
Last Modified: 2008-01-09
I am writing a program for pocketpc, using VS.net 2003
but i can only use Thd.start(), but can't use .Abort() or suspend

any way to solve this problem?

it is very urgent, extra points will be awarded...
thanks !!!
0
Comment
Question by:ho_alan
  • 2
4 Comments
 
LVL 21

Expert Comment

by:surajguptha
ID: 12492834
Because the .NET Compact Framework does not support the Thread.Abort and Thread.Stop methods, an application should stop all thread processes before allowing itself to close.
0
 
LVL 21

Assisted Solution

by:surajguptha
surajguptha earned 400 total points
ID: 12492837
0
 
LVL 3

Accepted Solution

by:
smallee earned 1600 total points
ID: 12493106
For reference

http://samples.gotdotnet.com/quickstart/CompactFramework/doc/controlinvoker.aspx




Closing threaded applications

Because the .NET Compact Framework does not support the Thread.Stop and Thread.Abort methods, you must be sure that no threads are running when you close a form. This QuickStart overrides the OnClosing method to cancel closing the form when the OK button, in the upper-right corner of the form, is clicked.

Note that a Pocket PC application with an OK button closes the form, and an application with an X button minimizes the form. For information about switching these buttons, see the Pocket PC Form Styles QuickStart. This QuickStart requires an OK button so that the Closing event is raised in order to use the OnClosing method.

Both the OnClosing and CloseButton_Click methods, as shown in the following code example, set the codeRequested variable to true. Only when the thread determines that this variable is true in the ThreadProc method does the thread close the form. The thread closes the form by using ControlInvoker.Invoke to invoke the CloseForm method.


// Set the closeRequested variable to true. This ensures that the
// Close button will not allow the application to close unless
// the thread has stopped running. When the ThreadProc method
// determines that closeRequested is true, it closes the application.
private void CloseButton_Click(object sender, System.EventArgs e) {
      closeRequested = true;
}

// The OnClosing override is called when the user clicks the OK
// button so that the application does not close until the thread
// has stopped running.
protected override void OnClosing(CancelEventArgs e)
{
   if (this.threadRunning)      
   {
      e.Cancel = true;
      MessageBox.Show("Application will close when thread has stopped running.");
   }
  closeRequested = true;
}





0
 
LVL 5

Author Comment

by:ho_alan
ID: 12493160
thanks all
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It seems a simple enough task, yet I see repeated questions asking how to do it: how to pass data between two forms. In this article, I will show you the different mechanisms available for you to do just that. This article is directed towards the .N…
Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
Integration Management Part 2
Screencast - Getting to Know the Pipeline
Suggested Courses
Course of the Month13 days, 18 hours left to enroll

580 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question