Note that there are some explanatory texts on larger screens.

plurals
  1. POThread Safe Control - Crashing VS 2008
    primarykey
    data
    text
    <p>I am working on creating a thread safe control for my windows forms application.</p> <p>I understand I can set the text on a control thread safe by using the following code:</p> <pre><code>private delegate void SetTextD(Control control, string value); private static void SetText(Control control, string value) { if(control.InvokeRequired) { control.Invoke(new SetTextD(SetText), new object[] {control, value}); } else { control.Text = value; } } </code></pre> <p>Then in my form code i can call:</p> <pre><code>SetText(lblStatus, "Updating..."); </code></pre> <p>My goal is to create a custom control, which inherits Label. Then inside this class, on the Text property I can just call:</p> <p>lblStatus.Text = "Updating..." </p> <p>Then it will automatically do the proper thread safe code.</p> <p>Here is the code that I have in my class:</p> <pre><code>public class ThreadSafeLabel : Label { private delegate string GetTextD(); private delegate void SetTextD(string value); private string GetText() { if (InvokeRequired) { return (string)Invoke(new GetTextD(GetText)); } return Text; } private void SetText(string value) { if(InvokeRequired) { Invoke(new SetTextD(SetText), new object[] {value}); } else { Text = value; } } public override string Text { get { return GetText(); } set { SetText(value); } } } </code></pre> <p>Now, when I attempt to add this control to my form, it crashes VS 2008. I was thinking that maybe it had to do with setting the initial text property when you add it to the form, but not sure.</p> <p>Any thoughts on what I might be doing wrong or what I might be missing?</p> <p>If something is not clear, please ask.</p> <p>Thanks!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload