How to prevent duplicates, macro or something?

Posted by blez on Stack Overflow See other posts from Stack Overflow or by blez
Published on 2010-05-08T13:07:10Z Indexed on 2010/05/08 13:08 UTC
Read the original article Hit count: 229

Filed under:
|
|

Well, the problem is that I've got a lot of code like this for each event passed to the GUI, how can I shortify this? Macros wont do the work I guess. Is there a more generic way to do something like a 'template' ?

private delegate void DownloadProgressDelegate(object sender, DownloaderProgressArgs e);
void DownloadProgress(object sender, DownloaderProgressArgs e) {
    if (this.InvokeRequired) {
        this.BeginInvoke(new DownloadProgressDelegate(DownloadProgress), new object[] { sender, e });
        return;
    }

    label2.Text = d.speedOutput.ToString();
}

private delegate void DownloadSpeedDelegate(object sender, DownloaderProgressArgs e);
void DownloadSpeed(object sender, DownloaderProgressArgs e) {
    if (this.InvokeRequired) {
        this.BeginInvoke(new DownloadSpeedDelegate(DownloadSpeed), new object[] { sender, e });
        return;
    }

    string speed = "";
    speed = (e.DownloadSpeed / 1024).ToString() + "kb/s";
    label3.Text = speed;
}

© Stack Overflow or respective owner

Related posts about c#

Related posts about preprocessor