Control.invoke with out parameter

Winforms, C #, VS2010.

I have a poll stream that works for the life of my application.

Sometimes it raises an event in my main form. I have not touched the code for many years, and it works successfully, but now I need to add the "out" parameter to the parameter list. I searched on the Internet, but all the topics that I found were thought-provoking and difficult to try to translate into my context. Mine does not use reflection.

Can someone help how to fix this pls? In the reflection streams that I read, people seem to check some array of objects for the result of the out result, which I don't use in my code, and I don't know where to get it anyway.

private bool OnNeedUpdateCreateEvent(string title, string message,
  bool creatingNew, out string newPlanName)
{
    newPlanName = "";

    // 1st pass through this function. 
    // Check to see if this is being called from another thread rather 
    // than the main thread. If so then invoke is required
    if (InvokeRequired)
    {
      // Invoke and recall this method.
      return (bool)Invoke(new onNeedToUpdatePlanEvent(OnNeedUpdateCreateEvent),
        title, message, creatingNew, out newPlanName); <- wrong out param

    }
    else
    {
      // 2nd pass through this function due to invoke, or invoke not required
      return InputDlg(this, title, message, creatingNew, out newPlanName);
    }

} 
+4
1

, , . . Invoke:

public object Invoke(
    Delegate method,
    params object[] args
)

params, . , . , :

if (!creatingNew) {
    // Invoke and recall this method.
    object[] args = new object[] { title, message, creatingNew, null };
    var retval = (bool)Invoke(new onNeedToUpdatePlanEvent(OnNeedUpdateCreateEvent), args);
    newPlanName = (string)args[3];
    return retval;
}
// etc..
+4

Source: https://habr.com/ru/post/1667861/


All Articles