Click here to Skip to main content
15,887,027 members
Home / Discussions / C#
   

C#

 
QuestionDatagridview Pin
yesu prakash8-Nov-10 22:12
yesu prakash8-Nov-10 22:12 
AnswerRe: Datagridview Pin
TweakBird8-Nov-10 23:59
TweakBird8-Nov-10 23:59 
QuestionReplace assembly at runtime Pin
marca2928-Nov-10 21:43
marca2928-Nov-10 21:43 
AnswerRe: Replace assembly at runtime Pin
David Ewen8-Nov-10 22:07
professionalDavid Ewen8-Nov-10 22:07 
AnswerRe: Replace assembly at runtime Pin
John Gathogo8-Nov-10 22:08
John Gathogo8-Nov-10 22:08 
GeneralRe: Replace assembly at runtime Pin
marca2928-Nov-10 22:18
marca2928-Nov-10 22:18 
AnswerRe: Replace assembly at runtime Pin
Pete O'Hanlon9-Nov-10 1:54
mvePete O'Hanlon9-Nov-10 1:54 
QuestionHow can I access my Mainwindow-controls from a thread? Pin
Erik8-Nov-10 20:45
Erik8-Nov-10 20:45 
Hi,

I am currently writing a gui-application, which does some processing in a thread. I pass a reference to my mainwindow to the thread, in order to make the thread set some text inside the mainwindow. However, when I try to access any control in my mainwindow from my thread, I get:

"An unhandled exception of type 'System.InvalidOperationException' occurred in WindowsBase.dll"

Simple question: what is the best way to access mainwindo-gui elements from a thread?

This is what my code looks like:

public MainWindow()
     {
         InitializeComponent();
         _ProcessHelperThread = new System.Threading.Thread(ProcessHelperThread);
         _ProcessHelperThread.Start();
     }

     void ProcessHelperThread()
     {
         Processes.Init(this); //this is a reference to my mainwindow
         //run the processes defined in Startup configuration
         Processes.Startup();
     }


Inside the thread (i.e. in my Processes-object), my app crashes when I try something like this:

public int Init(MainWindow window)
   {
       window.textBlock1.Text = Waittext; //Exception
   }


What is a better way to do this?
AnswerRe: How can I access my Mainwindow-controls from a thread? Pin
David Ewen8-Nov-10 21:06
professionalDavid Ewen8-Nov-10 21:06 
GeneralRe: How can I access my Mainwindow-controls from a thread? Pin
David Ewen8-Nov-10 21:14
professionalDavid Ewen8-Nov-10 21:14 
GeneralRe: How can I access my Mainwindow-controls from a thread? Pin
Erik8-Nov-10 21:50
Erik8-Nov-10 21:50 
QuestionDatagridview Pin
yesu prakash8-Nov-10 20:41
yesu prakash8-Nov-10 20:41 
AnswerRe: Datagridview Pin
David Ewen8-Nov-10 20:50
professionalDavid Ewen8-Nov-10 20:50 
QuestionSocket and Thread Question Pin
jason_mf8-Nov-10 18:45
jason_mf8-Nov-10 18:45 
AnswerRe: Socket and Thread Question Pin
Rajesh Anuhya8-Nov-10 18:55
professionalRajesh Anuhya8-Nov-10 18:55 
GeneralRe: Socket and Thread Question Pin
jason_mf8-Nov-10 18:58
jason_mf8-Nov-10 18:58 
QuestionMultiThreading Pin
RoboAlex8-Nov-10 17:26
RoboAlex8-Nov-10 17:26 
AnswerRe: MultiThreading Pin
Luc Pattyn8-Nov-10 17:31
sitebuilderLuc Pattyn8-Nov-10 17:31 
GeneralRe: MultiThreading Pin
Rajesh Anuhya8-Nov-10 18:57
professionalRajesh Anuhya8-Nov-10 18:57 
AnswerRe: MultiThreading Pin
David Skelly8-Nov-10 22:27
David Skelly8-Nov-10 22:27 
AnswerRe: MultiThreading Pin
Luc Pattyn9-Nov-10 1:37
sitebuilderLuc Pattyn9-Nov-10 1:37 
QuestionReturn all form controls to default state Pin
kruegs358-Nov-10 17:20
kruegs358-Nov-10 17:20 
AnswerRe: Return all form controls to default state Pin
Luc Pattyn8-Nov-10 17:26
sitebuilderLuc Pattyn8-Nov-10 17:26 
QuestionCan you gain administrator permission in .NET program? Pin
John Kenedy S.Kom8-Nov-10 16:08
John Kenedy S.Kom8-Nov-10 16:08 
AnswerRe: Can you gain administrator permission in .NET program? Pin
Jacob D Dixon8-Nov-10 17:44
Jacob D Dixon8-Nov-10 17:44 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.