Control.Invoke must be used to interact with controls created on a seperate thread
-
Hi, I get this error despite create a delegate..
private delegate void ResumeChart(); ResumeChart ChartResume; private void ResumeChartLayout() { this.m\_ChartControl.ResumeChartLayout(); } void ResetChart() { this.Invoke(ChartResume); }
Inside my constructor I have this.
public frmGraph(String stockQuote,String\[\] args) { InitializeComponent(); newArgs = new String\[args.Length\]; Array.Copy(args, newArgs, args.Length); token = newArgs\[0\]; this.stockQuote = stockQuote; //this.stockQuote = "MGM"; label1.Text = stockQuote; this.Text = stockQuote + " Graph"; **ChartResume = ResumeChartLayout;** }
Inside my form load, i create a new thread to call another function
private void frmGraph\_Load(object sender, EventArgs e) { FillDataTable(); //SetFilter(DateTime.Now.AddDays(-9), DateTime.Now); m\_ChartControl.Charts\[0\].Data = this.GenareteDataForCandle(); m\_ChartControl.SuspendChartLayout(); m\_ChartControl.LoadTheme("Manco.Chart.CF.Theme.xml"); m\_ChartControl.Charts\[0\].ChartType = ChartType.Line; m\_ChartControl.Charts\[0\].ValueAxisList\[0\].Min = this.m\_dStokMin; m\_ChartControl.Charts\[0\].ValueAxisList\[0\].Max = this.m\_dStokMax; **workerThread2 = new Thread(new ThreadStart(AddAnnotations)); workerThread2.Start();** m\_ChartControl.ResumeChartLayout(); }
This is my AddAnnotation function that will invoke the ResetChart() method
public void AddAnnotations() { string toa = "calls"; Annotation\[\] anno = null; int countA = 0; int arrayIndex = 0; while (true) { XmlDocument xmlPlogs = getAllPlogs(toa); XmlNodeList plogs = xmlPlogs.SelectNodes("/PlogList/Plog"); foreach (XmlNode plog in plogs) { XmlNodeList receivers = plog.SelectNodes("PlogUnique/Message/Receiver"); foreach (DateTime dt in dateArray) { DateTime newDT = Convert.ToDateTime(plog.SelectSingleNode("PlogCommon/T
-
Hi, I get this error despite create a delegate..
private delegate void ResumeChart(); ResumeChart ChartResume; private void ResumeChartLayout() { this.m\_ChartControl.ResumeChartLayout(); } void ResetChart() { this.Invoke(ChartResume); }
Inside my constructor I have this.
public frmGraph(String stockQuote,String\[\] args) { InitializeComponent(); newArgs = new String\[args.Length\]; Array.Copy(args, newArgs, args.Length); token = newArgs\[0\]; this.stockQuote = stockQuote; //this.stockQuote = "MGM"; label1.Text = stockQuote; this.Text = stockQuote + " Graph"; **ChartResume = ResumeChartLayout;** }
Inside my form load, i create a new thread to call another function
private void frmGraph\_Load(object sender, EventArgs e) { FillDataTable(); //SetFilter(DateTime.Now.AddDays(-9), DateTime.Now); m\_ChartControl.Charts\[0\].Data = this.GenareteDataForCandle(); m\_ChartControl.SuspendChartLayout(); m\_ChartControl.LoadTheme("Manco.Chart.CF.Theme.xml"); m\_ChartControl.Charts\[0\].ChartType = ChartType.Line; m\_ChartControl.Charts\[0\].ValueAxisList\[0\].Min = this.m\_dStokMin; m\_ChartControl.Charts\[0\].ValueAxisList\[0\].Max = this.m\_dStokMax; **workerThread2 = new Thread(new ThreadStart(AddAnnotations)); workerThread2.Start();** m\_ChartControl.ResumeChartLayout(); }
This is my AddAnnotation function that will invoke the ResetChart() method
public void AddAnnotations() { string toa = "calls"; Annotation\[\] anno = null; int countA = 0; int arrayIndex = 0; while (true) { XmlDocument xmlPlogs = getAllPlogs(toa); XmlNodeList plogs = xmlPlogs.SelectNodes("/PlogList/Plog"); foreach (XmlNode plog in plogs) { XmlNodeList receivers = plog.SelectNodes("PlogUnique/Message/Receiver"); foreach (DateTime dt in dateArray) { DateTime newDT = Convert.ToDateTime(plog.SelectSingleNode("PlogCommon/T
-
Try after changing the ResetChart function like this.
void ResetChart() { this.m_ChartControl.Invoke(ChartResume); }
hmm.. i still get the same error :( could this be the error? under the AddAnnotations method. anno[countA] = m_ChartControl.Charts[0].AnnotationList.CreateAnnotation();
-
hmm.. i still get the same error :( could this be the error? under the AddAnnotations method. anno[countA] = m_ChartControl.Charts[0].AnnotationList.CreateAnnotation();
Yes. Previously I did not went through the AddAnnotation() function. Since you ChartControl is in the UI Thread, you can only access/modify the ChartControl properties by using a delegate. Just like you used a delegate to call the ChartResume method, use another Delegate to add annotation. This will surely solve the problem.
-
Yes. Previously I did not went through the AddAnnotation() function. Since you ChartControl is in the UI Thread, you can only access/modify the ChartControl properties by using a delegate. Just like you used a delegate to call the ChartResume method, use another Delegate to add annotation. This will surely solve the problem.
i have create another Delegate
private delegate void AddAnnotation(); AddAnnotation addNewAnnotation; private void CreateAnnotation() { m\_ChartControl.Charts\[0\].AnnotationList.CreateAnnotation(); } void cAnnotation() { this.Invoke(addNewAnnotation); }
and under the AddAnnoations method i change it to
anno[countA] = cAnnotation();
and i get this error Error 4 Cannot implicitly convert type 'void' to 'Manco.Chart.CF.Layout.Annotation' i tried change all the void to Annotation but still get error
modified on Friday, December 11, 2009 12:00 PM