Hi I am trying to update a label in my WPF GUI from another class, which is not the GUI with this code:   System.Windows.Threading.Dispatcher.CurrentDispatcher.Invoke(new Action(() =&gt;       {          ((MainWindow)System.Windows.Application.Current.MainWindow)              .lblError.Content = exception.Message;       }));   Sometimes however I get the following exception and the update does not work:     Exception thrown: 'System.InvalidOperationException' in   WindowsBase.dll (" The calling thread can not access this object   because the object is owned by another thread .")   Why does my delegate not work? Is there an easy way to do what I want to do (update a label of my GUI from another class) without too much effort?
12750
Which is the simplest way to update a Label from another Thread?   I have a Form running on thread1, and from that I'm starting another thread (thread2).  While thread2 is processing some files I would like to update a Label on the Form with the current status of thread2's work.   How could I do that?
74428
All I want is to update an ListViewItem's text whithout seeing any flickering.  This is my code for updating (called several times):  listView.BeginUpdate(); listViewItem.SubItems[0].Text = state.ToString();    // update the state listViewItem.SubItems[1].Text = progress.ToString(); // update the progress listView.EndUpdate();   I've seen some solutions that involve overriding the component's WndProc():  protected override void WndProc(ref Message m) {     if (m.Msg == (int)WM.WM_ERASEBKGND)     {         m.Msg = (int)IntPtr.Zero;     }     base.WndProc(ref m); }   They say it solves the problem, but in my case It didn't. I believe this is because I'm using icons on every item.
122124
I'm trying to bind a list of custom objects to a WPF Image like this:  &lt;Image&gt;     &lt;Image.Source&gt;         &lt;BitmapImage UriSource="{Binding Path=ImagePath}" /&gt;     &lt;/Image.Source&gt; &lt;/Image&gt;   But it doesn't work. This is the error I'm getting:  "Property 'UriSource' or property 'StreamSource' must be set."  What am I missing?
65095
Is there a way to show the console in a Windows application?  I want to do something like this:  static class Program {     [STAThread]     static void Main(string[] args) {         bool consoleMode = Boolean.Parse(args[0]);          if (consoleMode) {             Console.WriteLine("consolemode started");             // ...         } else {             Application.EnableVisualStyles();             Application.SetCompatibleTextRenderingDefault(false);             Application.Run(new Form1());         }     } }
104655
How can I add a newline in the text of a label in WPF such as the following?  &lt;Label&gt;Lorem    ipsum&lt;/Label&gt;
38358
I've been learning C#, and I'm trying to understand lambdas.  In this sample below, it prints out 10 ten times.  class Program {     delegate void Action();     static void Main(string[] args)     {         List&lt;Action&gt; actions = new List&lt;Action&gt;();          for (int i = 0; i &lt; 10; ++i )             actions.Add(()=&gt;Console.WriteLine(i));          foreach (Action a in actions)             a();     } }   Obviously, the generated class behind the lambda is storing a reference or pointer to the int i variable, and is assigning a new value to the same reference every time the loop iterates.  Is there a way to force the lamda to grab a copy instead, like the C++0x syntax  [&amp;](){ ... } // Capture by reference   vs.  [=](){ ... } // Capture copies
84091
ok, ive a class and i pass an object as property.  the object that i pass is a List&lt;X&gt;  in my class im trying to access the Object index by reflection BUT I CAN'T!!!   Example:  this class works i just wrote down the part i want to show you and i need help.  class MyClass {     private object _recordSet;     public object RecordSet     {         get { return _recordSet; }         set { _recordSet = value; }     }      public string Draw()     {         system.reflection.Assembly asem = system.reflection.Assembly.getAssembly(_dataSource.GetType());          object instance;          instance = asem.CreateInstance(_dataSource.GetType().UnderlyingSystemType.FullName);          //to access de Count of my List         int recordcount = int.Parse(_dataSource.GetType().GetProperty("Count").GetValue(_dataSource,null));          //i need to do a          for(int cont = 0; cont &lt; recordCount; cont++)         {             _dataSource[cont].Name; // &lt;-- THIS PART IS NOT WORKING!!! because i cant access the Index Directly.... WHAT TO DO!! ???         }     } }
17824
I had one batch class in which i am passing some data required for creating object record.But when i call that batch class from parent class variables are initialized but start method are not called as there is no record to query i also tried with iterable object but not able to do that.My code is as below  global class testBatchClass implements Database.Batchable&lt;SObject&gt;,Database.Stateful{     public List&lt;sObject&gt; sObjectList;     public string objectName;     public String dataList;      public testBatchClass(String objectName,String inputdata){          String listType = 'List&lt;'+objectName+'&gt;';         system.debug('list type value is'+listType);         List&lt;SObject&gt; castRecords = (List&lt;SObject&gt;)Type.forName(listType).newInstance();         this.sObjectList = castRecords;         this.objectName = objectName;         this.dataList = inputdata;      }     global Iterable&lt;SObject&gt; start(Database.BatchableContext batchableContext) {         return new sObjectList{};     }     global void execute(Database.BatchableContext batchableContext, List&lt;sobject&gt; scope){          List&lt;OpportunityRenewal__mdt&gt; mdtList = new List&lt;OpportunityRenewal__mdt&gt;([Select id,Api_Name_of_Fields__c,Sobject_Name__c from TestFileUploadCustomSetting1__mdt where Sobject_Name__c=:objectName]);         List&lt;String&gt; fieldName = new List&lt;String&gt;();         for(OpportunityRenewal__mdt md : mdtList){             if(md.Sobject_Name__c == objectName){                 fieldName = md.Api_Name_of_Fields__c.Split(',');                 break;             }         }         List&lt;String&gt; dataRowsSplit= dataList.split(',');         dataRowsSplit.remove(0);         for(String eachRow: dataRowsSplit){             List&lt;String&gt; splitString = eachRow.Split(',');             sObject sobj = Schema.getGlobalDescribe().get(objectName).newSObject();             for(Integer i=0; i &lt;= splitString.Size(); i++){                 sobj.put(fieldName[i],splitString[i]);             }             scope.add(sobj);         }         if(scope != Null &amp;&amp; scope.Size() &gt; 0){             upsert scope;         }     }      global void finish(Database.BatchableContext batchableContext) {} }   Thanks
17471
I'm getting the error below when trying to loop through a listbox and then remove the item.     List that this enumerator is bound to has been modified. An enumerator can only be used if the list does not change.   foreach (string s in listBox1.Items) {     MessageBox.Show(s);     //do stuff with (s);     listBox1.Items.Remove(s); }   How can I remove the item and still loop through the contents?
57041
Can someone explain me, why object binding is not working?  cmpOne.cmp  &lt;aura:component extensible="true" abstract="true" access="global"&gt;     &lt;aura:attribute name="testObject" type="Account" access="global"/&gt;      &lt;span&gt;         {!v.body}     &lt;/span&gt; &lt;/aura:component&gt;   cmpOneFirst.cmp  &lt;aura:component extends="c:cmpOne" access="global"&gt;       &lt;ui:inputText value="{!v.testObject.Name}" /&gt;  &lt;/aura:component&gt;   cmpOneSecond.cmp  &lt;aura:component extends="c:cmpOne" access="global"&gt;     &lt;aura:attribute name="types" type="Aura.Component[]" access="global"/&gt;     {!v.types} &lt;/aura:component&gt;   cmpOneThird.cmp  &lt;aura:component extends="c:cmpOne" access="global"&gt;     // value of field should be changed, as  this value  is changing  in  inner component     {!v.testObject.Name} &lt;br/&gt;       &lt;c:cmpOneSecond&gt;         &lt;aura:set attribute="types"&gt;             &lt;c:cmpOneFirst testObject="{!v.testObject}"/&gt;         &lt;/aura:set&gt;     &lt;/c:cmpOneSecond&gt; &lt;/aura:component&gt;   No controllers.   Desired behaviour: when  you change value of  name field in cmpOneFirst.cmp, new value is displayed in cmpOneThird.cmp   If you change type of testObject attribute from Account to String - binding works.  Any suggestions?
80656
I want do something like this:  Button btn1 = new Button(); btn1.Click += new EventHandler(btn1_Click); Button btn2 = new Button(); // Take whatever event got assigned to btn1 and assign it to btn2. btn2.Click += btn1.Click; // The compiler says no...   Where btn1_Click is already defined in the class:  void btn1_Click(object sender, EventArgs e) {     // }   This won't compile, of course ("The event 'System.Windows.Forms.Control.Click' can only appear on the left hand side of += or -="). Is there a way to take the event handler from one control and assign it to another at runtime? If that's not possible, is duplicating the event handler and assigning it to another control at runtime doable?  A couple of points: I have googled the heck out of this one for awhile and found no way of doing it yet. Most of the attempted approaches involve reflection, so if you read my question and think the answer is incredibly obvious, please try to compile the code in Visual Studio first. Or if the answer really is incredibly obvious, please feel free to slap me with it. Thanks, I'm really looking forward to seeing if this is possible.  I know I could just do this:  btn2.Click += new EventHandler(btn1_Click);   That's not what I'm looking for here.  This is also not what I'm looking for:  EventHandler handy = new EventHandler(btn1_Click); Button btn1 = new Button(); btn1.Click += handy; Button btn2 = new Button(); btn2.Click += handy;
5057
I have a child form that is throwing an ApplicationException in the Load event handler (intentionally for testing purposes).  The parent form wraps the ChildForm.Show() method in a Try...Catch ex As Exception block.  The catch block simply displays a message and closes the child form.  All works as expected when debugged in visual studio 2008 (.net 3.5 sp1).  However, when I run it outside of visual studio, the Catch block seems to get missed and an unhandled exception occurs.  Any idea why that is?  Thank you.  Example Code:  Public Class Form1      Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click         Dim f2 As Form2          f2 = New Form2          Try             MessageBox.Show("Opening form 2")             f2.ShowDialog()         Catch ex As Exception             f2.Close()             MessageBox.Show("Form 2 closed.")         End Try     End Sub  End Class  Public Class Form2      Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load         Throw New ApplicationException("Test Form_Load")     End Sub      Public Sub New()          ' This call is required by the Windows Form Designer.         InitializeComponent()          ' Add any initialization after the InitializeComponent() call.     End Sub  End Class   Stack Trace:    System.ApplicationException:  Test Form_Load   at WindowsApplication1.Form2.Form2_Load(Object sender, EventArgs e)  in UnhandledExceptionTest2\WindowsApplication1\Form2.vb  System.Windows.Forms.Form.OnLoad(EventArgs e)  System.Windows.Forms.Form.OnCreateControl()  System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)  System.Windows.Forms.Control.CreateControl()  System.Windows.Forms.Control.WmShowWindow(Message& m)    at  System.Windows.Forms.Control.WndProc(Message&> m)    at  System.Windows.Forms.ScrollableControl.WndProc(Message&> m)    at  System.Windows.Forms.ContainerControl.WndProc(Message&> m)    at  System.Windows.Forms.Form.WmShowWindow(Message&> m)    at  System.Windows.Forms.Form.WndProc(Message&> m)    at  System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message&> m)    at  System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message&> m)    at  System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr  lparam)
17111
Just wondering what the difference between BeginInvoke() and Invoke() are?   Mainly what each one would be used for.  EDIT: What is the difference between creating a threading object and calling invoke on that and just calling BeginInvoke() on a delegate? or are they the same thing?
4696
What are the differences between delegates and an events? Don't both hold references to functions that can be executed?
73786
I'd like to update the label of an operator when it's called. But this :  def execute(self,context):     self.bl_label = "good night"   ... apparently doesn't work if the bl_label property has already been defined. Am I wrong ?
47851
What does InitializeComponent() do, and how does it work in WPF?  In general first, but I would especially be interested to know the gory details of order of construction, and what happens when there are Attached Properties.
31102
The example below throws an InvalidOperationException, "Collection was modified; enumeration operation may not execute." when executing the code.   var urls = new List&lt;string&gt;(); urls.Add("http://www.google.com");  foreach (string url in urls) {     // Get all links from the url     List&lt;string&gt; newUrls = GetLinks(url);      urls.AddRange(newUrls); // &lt;-- This is really the problematic row, adding values to the collection I'm looping }   How can I rewrite this in a better way? I'm guessing a recursive solution?