Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Sorry for the late reply.</p> <p>First of all thank you for your quick and helpful responses.</p> <p>The tip that's not possible </p> <blockquote> <p>do anything to a Form or Control from a worker thread</p> </blockquote> <p>helped me a lot.</p> <p>I usually not doing GUI programming for Microsoft's Windows and so I'm not so familiar with it.</p> <p>So I reconsidered the previous source code because I wanted to solve the actual problem (not doing GUI things from a worker thread) and would like to have a clean and logical code structure.</p> <p>Therefore I've read in the topics of Window's Component Object Model (COM) and the used threading model:</p> <ul> <li>What is COM: <a href="http://www.microsoft.com/com/default.mspx" rel="nofollow">http://www.microsoft.com/com/default.mspx</a></li> <li>Understanding and Using COM Threading Models: <a href="http://msdn.microsoft.com/en-us/library/ms809971.aspx" rel="nofollow">http://msdn.microsoft.com/en-us/library/ms809971.aspx</a></li> <li>Understanding The COM Single-Threaded Apartment Part 1: <a href="http://www.codeproject.com/KB/COM/CCOMThread.aspx" rel="nofollow">http://www.codeproject.com/KB/COM/CCOMThread.aspx</a></li> </ul> <p>Now the code looks like this:</p> <p>The <strong>main window</strong> ("UI thread") is started in <code>ApartmentState STA</code></p> <pre><code>... ThreadStart threadStart = delegate { RunMainWindow(mainWindow); }; Thread mainWindowThread = new Thread(threadStart); mainWindowThread.SetApartmentState(ApartmentState.STA); mainWindowThread.Start(); ... </code></pre> <p><strong>"Save" button</strong> event handler (main window):</p> <pre><code>private void bSave_Click(object sender, EventArgs e) { OpenSaveFileDialog(); } </code></pre> <p>Method "<strong>OpenSaveFileDialog</strong>" (main window):</p> <pre><code>private void OpenSaveFileDialog() { SaveFileDialog saveFileDialog = new SaveFileDialog(); ... DialogResult pressedButton = saveFileDialog.ShowDialog(); ... } </code></pre> <p>There is still space for optimizations (for sure), but I'm comfortable with this - preliminary - result.</p> <p>So thanks a lot for your help.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload