.net - Cancel a .C# Net BackgroundWorker blocked on I/O operation -


i'm required use framework 3.5. want test whether file on computer named bob exists. i'm using backgroundworker , file.exists(filename). if bob offline call block tens of seconds. abort() , interrupt() have no effect while worker waiting call file.exists() return. i'd interrupt file.exists() immediately. can suggest way doesn't involve p/invoke?

thanks.

to clarify, need periodically check see whether file available. can't know whether remote computer configured respond pings. i'm running standard user, not admin. have no access remote system administrators.

it looks framework 4.0 or 4.5 has async capability i'm restricted 3.5.

editing add test program:

// first call file.exists waits @ least 20 seconds first time // remote computer taken off line. demonstrate, set testfile name // of file on remote computer , start program. disable  // remote computer's network connection. each time disable test // program pauses. in test local computer runs win8 , remote winxp // in virtualbox vm. using system; using system.io; using system.threading; using system.componentmodel; namespace block2 {     class program     {         static void main(string[] args)         {             autoresetevent autoresetevent = new autoresetevent(false);             backgroundworker worker = new backgroundworker();             worker.dowork += dowork;             worker.runworkerasync(autoresetevent);             log("main - waiting");             autoresetevent.waitone();             log("main - finished");         }          static void dowork(object sender, doworkeventargs e)         {             const string testfile = @"p:\testfile.txt";             (int x = 0; x < 100; x++)             {                 if (file.exists(testfile))                     log("  -- worker: file exists");                 else                     log("  -- worker: file doesn't exist");                 thread.sleep(1000);             }             ((autoresetevent)e.argument).set();         }          static void log(string msg)         {             console.writeline(datetime.now.tolocaltime().tostring()+": "+ msg);         }     } } 

follow these steps:

  1. first check if remote computer online: how can check if computer on network online?

  2. if online go ahead checking file.exists(), else abort operation.


Popular posts from this blog

c# - ODP.NET Oracle.ManagedDataAccess causes ORA-12537 network session end of file -

matlab - Compression and Decompression of ECG Signal using HUFFMAN ALGORITHM -

utf 8 - split utf-8 string into bytes in python -