public void pastPanelInit()
{
var threadParameters = new ThreadStart(initSpreadSheet);
var thread2 = new Thread(threadParameters);
thread2.SetApartmentState(ApartmentState.STA);
thread2.Start();
//thread2.Join();
}
private void initSpreadSheet()
{
if (pastTabCalender.InvokeRequired)
{
pastTabCalender.Invoke(new Action(() => initSpreadSheet()));
}
else
{
spreadSheet = new RadSpreadsheet();
spreadSheet.Dock = DockStyle.Fill;
spreadSheet.Anchor = AnchorStyles.Top | AnchorStyles.Left;
spreadSheet.Workbook.Worksheets.Add();
pastTabCalender.Controls.Add(spreadSheet);
}
}
{
var threadParameters = new ThreadStart(initSpreadSheet);
var thread2 = new Thread(threadParameters);
thread2.SetApartmentState(ApartmentState.STA);
thread2.Start();
//thread2.Join();
}
private void initSpreadSheet()
{
if (pastTabCalender.InvokeRequired)
{
pastTabCalender.Invoke(new Action(() => initSpreadSheet()));
}
else
{
spreadSheet = new RadSpreadsheet();
spreadSheet.Dock = DockStyle.Fill;
spreadSheet.Anchor = AnchorStyles.Top | AnchorStyles.Left;
spreadSheet.Workbook.Worksheets.Add();
pastTabCalender.Controls.Add(spreadSheet);
}
}
Im having some trouble adding a spreadsheet to my RadPageViewPage since the spreadsheet requires to be on a thread. This still gives me 'Cross-thread operation not valid: Control '' accessed from a thread other than the thread it was created on.'.
Is there anyone that could explain what im doing wrong here? Thanks.
Edit. Updated the code a bit and this gives me that it requires to be on the STA thread. Its something im not understanding with these threadings in c#.
var threadParameters = new ThreadStart(() => { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new ExpressTransportForm()); }); var thread2 = new Thread(threadParameters); thread2.SetApartmentState(ApartmentState.STA); thread2.Start();