I am very confused here and not sure if the framework (4.0) supports some of the answers I found so far online.
I have the following structure
public class Form1()
{
public int GenerateID(OtherThreadObj oto)
{
int result;
if (this.InvokeRequired)
{
return (int)this.Invoke((MethodInvoker)delegate { GenerateIDSafe(oto); });
// now this doesn't work obviously. I was looking at .begininvoke, end, etc and got really lost there
}
else
{
return GenerateIDSafe(oto);
}
}
private int GenerateIDSafe(OtherThreadObj oto)
{
return oto.id.ToSuperID(); // Assume ToSuperID some extension method.
}
}
Now the Idea is to call The Generate ID from another Thread and get
that return value.
public class OtherThreadObj
{
private Form1 parentform;
private int GetSuperID()
{
return parentform.GenerateID(this);
}
}
so obviously the above is no good because I don’t get the right return on the .Invoke. I am totally lost on how to do this properly.
You were almost there: