PC Review


Reply
Thread Tools Rating: Thread Rating: 1 votes, 1.00 average.

How to close an application when a button is clicked even when the application is running another process?

 
 
Anderson Takemitsu Kubota
Guest
Posts: n/a
 
      21st Jul 2003
Hi!

I need to run a process that should take over 1 minute, for instance.
I desire to put a button that the user can cancel the process.
For this, I was using the Application.DoEvents in the first process, and several times I verify the value of a m_bCancel variable that informs when the user requests the application to cancel.

This is the code I've being implementing on the cancel button is something like this:

private void btnCancel_Click(object sender, System.EventArgs e)
{
if(m_bRunning)
{
AddStatus("Process is being aborted...");
m_MainProcess.SetCancel(true);
int nCount = 0;
while(nCount < 5)
{
Application.DoEvents();
if(m_bRunning)
Thread.Sleep(1000);
else
break;
nCount++;
}
}
m_bCancel = true;
FinishProcess();
this.Close();
this.Dispose();
Application.Exit();
}

The problem is that the application remains on memory even after the Application.Exit() statement is executed.
Is it possible to do what I desire in a single thread?

Thank you.

Anderson T. Kubota

 
Reply With Quote
 
 
 
 
Alex Yakhnin [eMVP]
Guest
Posts: n/a
 
      21st Jul 2003
What are you doing in your worker thread MainProcess when
making a call to SetCancel?

-Alex
Alex Yakhnin, Microsoft Embedded MVP
IntelliProg, Inc.
http://www.intelliprog.com
"Check out our Compact Framework controls..."

>-----Original Message-----
>Hi!
>
>I need to run a process that should take over 1 minute,

for instance.
>I desire to put a button that the user can cancel the

process.
>For this, I was using the Application.DoEvents in the

first process, and several times I verify the value of a
m_bCancel variable that informs when the user requests the
application to cancel.
>
>This is the code I've being implementing on the cancel

button is something like this:
>
>private void btnCancel_Click(object sender,

System.EventArgs e)
>{
> if(m_bRunning)
> {
> AddStatus("Process is being aborted...");
> m_MainProcess.SetCancel(true);
> int nCount = 0;
> while(nCount < 5)
> {
> Application.DoEvents();
> if(m_bRunning)
> Thread.Sleep(1000);
> else
> break;
> nCount++;
> }
> }
> m_bCancel = true;
> FinishProcess();
> this.Close();
> this.Dispose();
> Application.Exit();
>}
>
>The problem is that the application remains on memory

even after the Application.Exit() statement is executed.
>Is it possible to do what I desire in a single thread?
>
>Thank you.
>
>Anderson T. Kubota
>

 
Reply With Quote
 
MichaelLipp[MS]
Guest
Posts: n/a
 
      19th Aug 2003
The problem is your appliaction is closing before the thread is really done.

There's a QuickStart sample which shows how your application can wait to
close until the thread is *really* done:

http://samples.gotdotnet.com/quickst...controlinvoker.
aspx



NETCF Beta FAQ's -- http://www.gotdotnet.com/team/netcf/FAQ.aspx
This posting is provided "AS IS" with no warranties, and confers no rights.

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Excel Application Window Tiling when Help is clicked on and application is not set to maximize Ronald R. Dodge, Jr. Microsoft Excel Discussion 0 12th Aug 2009 07:21 PM
While Running How To Restart Application As If Clicked Executable Christopher Lusardi Microsoft VB .NET 1 25th May 2006 03:28 PM
How Kill Running Application Process =?Utf-8?B?U3RldmUgQi4=?= Microsoft C# .NET 4 15th Jul 2005 01:33 PM
running application in asp.net process. Anders Both Microsoft ASP .NET 6 20th Dec 2003 08:30 PM
Windows application does not close when i press the close button Umut Tezduyar Microsoft Dot NET Framework Forms 7 14th Aug 2003 08:57 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 12:35 PM.