Click here to Skip to main content
15,902,189 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i use this code:
C#
private void BW_DoWork(object sender, DoWorkEventArgs e)
       {
       
           if (BW.CancellationPending)
           {
               e.Cancel = true;
               return;
           }
               MainPage MP = new MainPage();
               MP.thisconnection.Open();
               MP.ShowDialog();

       }

but canclation button don't work.
How i can cancle operation before it's complete?
Posted

Setting the cancel property does nothing, unless your thread also checks the property and decides to stop processing. It's a way of sending a message, not a way to kill a thread no matter what it's doing ( and has half done at that point ). this allows you to deal with the object you're working on and perform any clean up code.

To be more specific, you need to press cancel the MOMENT your thread starts, for this code to work, because otherwise, MainPage is showing, and does not have access to the event args, again. You want to add a handler for the progress event, and call it regularly, then it is where you check this property.
 
Share this answer
 
v2
 
Share this answer
 
Comments
_Amy 4-Aug-12 23:47pm    
I don't know what is wrong withe people out here. simply downvoted my 5 answers. Where I did mistake?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900