2PTTechnology

The platform that enables you to build rich, interactive communities
Welcome to 2PTTechnology Sign in | Join | Help
in Search

Update form from another thread without creating delegates

Last post 01-18-2010, 8:38 AM by pskobel. 0 replies.
Sort Posts: Previous Next
  •  01-18-2010, 8:38 AM 307

    Update form from another thread without creating delegates

    static class StaticClass
        {
            public static void SafeThreadAction<T>(this T form, Action<T> call) where T : System.Windows.Forms.Form
            {
                form.BeginInvoke(call, form);
            }


            public static Y SafeThreadGet<T, Y>(this T form, Func<T, Y> call) where T : System.Windows.Forms.Form
            {
                IAsyncResult result = form.BeginInvoke(call, form);
                object result2 = form.EndInvoke(result);
                return (Y)result2;
            }
        }

     Example - Calls

    StaticClass.SafeThreadAction(this, frm => frm.txtCaseCount.Text = "count 2");

    string textboxtext = StaticClass.SafeThreadGet(this, frm => frm.txtCaseCount.Text);

View as RSS news feed in XML
Powered by Community Server (Personal Edition), by Telligent Systems