简体   繁体   中英

how to get an event whenever the network cable is connected or disconnected

im doing an application in which im transfering file through FTP.i succesfully done all the things to transfer files and folders.now i want to know how to get an event whenever the the network cable is connected or disconnected while im transfering a file.

im using SYSTEM.NET NAMESPACE,FTPWEBREQUEST Class.

when will the event get raised i just run mi program and disconnected the network cable but nothing happens.

im not able to raise the event will u send ur code .actually it is working in vb.net.it doesnt get raised in c# below is mycode:

public partial class Form1 : Form
{
    public static event NetworkAvailabilityChangedEventHandler networkchanged;
    string file_to_upload;
    string serverip;
    string username;
    string password;
    FileStream fstream;
    Stream strem;

    public Form1()
    {
        InitializeComponent();
        networkchanged += new NetworkAvailabilityChangedEventHandler(Form1_networkchanged);


    }

    void Form1_networkchanged(object sender, NetworkAvailabilityEventArgs e)
    {
        //my implementations goes here
        //throw new Exception("The method or operation is not implemented.");
    }

i done it this is very useful.thank you very much

You don't really need to handled the "network cable is disconnected" case. The FTP library you are using should /would time-out or give an error. What library/class are you using?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM