Kristofer Prennmark
Kristofer Prennmark

Reputation: 3

No overload for 'method' matches delegate 'delegate'

This is just a part of the code

A few lines down I'm trying to convert an Int to double. But the fact that the double is an array makes it hard...

I need to include "i" like I did in the previous function, but it wont work, and I get the following error;

No overload for 'webKoordx_OpenReadComplete' matches delegate 'System.Net.OpenReadCompletedEventHandler'

If you know any solution, or is able to see something I've missed, please help me!

private void getKoord(int i)
    {
        string stringKoX = "http://media.vgy.se/kristoferpk/spots/" + i + "/koordinatx.html";
        string stringKoY = "http://media.vgy.se/kristoferpk/spots/" + i + "/koordinaty.html";

        var webKoordx = new WebClient();
        webKoordx.OpenReadAsync(new Uri(stringKoX));
        webKoordx.OpenReadCompleted += new OpenReadCompletedEventHandler(webKoordx_OpenReadComplete);

        var webKoordy = new WebClient();
        webKoordy.OpenReadAsync(new Uri(stringKoY));
        webKoordy.OpenReadCompleted += new OpenReadCompletedEventHandler(webKoordy_OpenReadComplete);
    }

    void webKoordx_OpenReadComplete(object sender, OpenReadCompletedEventArgs e, int i)//<<-----
    {
        try
        {
            using (var reader = new StreamReader(e.Result))
            {
                koordx = reader.ReadToEnd();
                koordx_d[i] = Convert.ToDouble(koordx);
            }
        }
        catch
        {
            MessageBox.Show("Kan ej ansluta");
            MessageBox.Show("Kontrollera din anslutning");
        }
    }
    void webKoordy_OpenReadComplete(object sender, OpenReadCompletedEventArgs e)//<<-----
    {
        try
        {
            using (var reader = new StreamReader(e.Result))
            {
                koordy = reader.ReadToEnd();
                koordy_d[i] = Convert.ToDouble(koordy);
            }
        }
        catch
        {
            MessageBox.Show("Kan ej ansluta");
            MessageBox.Show("Kontrollera din anslutning");
        }
    }

Upvotes: 0

Views: 563

Answers (1)

SLaks
SLaks

Reputation: 887767

You cannot pass extra information to an event handler like that.

Instead, you can add a lambda expression that handles the event and passes your extra information from its closure:

webKoordx.OpenReadCompleted += (sender, e) => MyMethod(e.Result, i);

Upvotes: 1

Related Questions