c# - Problem with inheritance -


i created class:

public class abortablebackgroundworker : backgroundworker {      private thread workerthread;      protected override void ondowork(doworkeventargs e)     {         workerthread = thread.currentthread;         try         {             base.ondowork(e);         }         catch (threadabortexception)         {             e.cancel = true; //we must set cancel property true!             thread.resetabort(); //prevents threadabortexception propagation         }     }       public void abort()     {         if (workerthread != null)         {             workerthread.abort();             workerthread = null;         }     } } 

here how use it:

  backgroundworker1 = new abortablebackgroundworker(); //... backgroundworker1.runworkerasync();  if (backgroundworker1.isbusy == true) {     backgroundworker1.abort();//this method unavailable :(     backgroundworker1.dispose(); } 

another small question..will code cancel backgroundworker?

the method unavailable because static type of backgroundworker1 backgroundworker. need

abortablebackgroundworker backgroundworker1 = new abortablebackgroundworker(); 

otherwise you'll have downcast it(be (cast) or as) abortablebackgroundworker


Comments

Popular posts from this blog

linux - Using a Cron Job to check if my mod_wsgi / apache server is running and restart -

actionscript 3 - TweenLite does not work with object -

jQuery Ajax Render Fragments OR Whole Page -