المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : threading, invoke



C# Programming
12-13-2009, 01:53 AM
Hi,

I got this chart object on my UI thread called 'm_ChartControl'

I got a method called AddAnnotations that will be run on a new thread in my Form_Load method.

Inside my AddAnnotation method there is a line of code that do this.

Annotation a = m_ChartControl.Charts[0].AnnotationList.CreateAnnotation();

But m_ChartControl.Charts[0].AnnotationList.CreateAnnotation(); is in the UI thread.

How do i create a delegate to put it here?

I have tried this.

private delegate Annotation AddAnnotation();
AddAnnotation addNewAnnotation;
private Annotation CreateAnnotation()
{
return m_ChartControl.Charts[0].AnnotationList.CreateAnnotation();
}
void cAnnotation()
{
this.Invoke(addNewAnnotation);
}

I changed this to

Annotation a = cAnnotation();

and i get this error

Error 18 Cannot implicitly convert type 'void' to 'Manco.Chart.CF.Layout.Annotation'