c# - Cross-thread operation not valid : <p>i was facing the exception Cross-thread error on my methods (void) i solved them by :</p>

<pre><code>public delegate void onitemAdd(ListViewItem client);
public void OnItemAdd(ListViewItem itemtoadd)
{
    if (this.InvokeRequired)
    {
        onitemAdd adder = new onitemAdd(OnItemAdd);
        this.Invoke(adder, new object[] { itemtoadd });
    }
    else
    {
        if (itemtoadd != null)
        ClientsView.Items.Add(itemtoadd);
    }
}
</code></pre>

<p>but i don't know how can i do the same but to return the value returned in :</p>

<pre><code>public delegate ListViewItem ItemReturn(Client client);
public ListViewItem OnReturnitem(Client client)
{
    if (this.InvokeRequired)
    {
        ItemReturn itm = new Zserver.Form1.ItemReturn(OnReturnitem);
        this.Invoke(itm, new object[] { client });
        // need to return a value of the invoked method 
    }
    else
    {
        ListViewItem item = ClientsView.Items
         .Cast&lt;ListViewItem&gt;()
         .FirstOrDefault(x =&gt; x.SubItems[1].Text == client.IPadress);
        return item;
    }
}
</code></pre>
