Solved

WPF -  Can I have two "windows" working  at same time in the same solution?

Posted on 2014-04-07
4
878 Views
Last Modified: 2014-04-08
I'm working on an app that has a usercontrol that is reading at real time emails from Outlook and writing some information in a database. From time to time I want to launch a batch process, with final output on a datagrid  in another user control and comeback to the first one where I will be the most of times! My problem is that the "batch usercontrol" gets locked until the whole process finishes, not allowing me to return to the first. Inside each usercontrol I'm using threading! Can I use among usercontrols?
I'm also using WPF.MDI dll but  any solution is welcomed!
As a Proof of Concept programmer I Thanks in advance!
0
Comment
Question by:novreisb
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 34

Expert Comment

by:sarabande
ID: 39985670
generally, the batch process should run in a thread. when it returns with data, you may pass the data by PostMessage calls directed to the parent window of the controls (or an ui controller). the PostMessage would put the messages to the end of the current message queue and you would write a handler that catches the messages and updates the controls accordingly.

alternatively, your thread could put the data into a shared container, and your ui has a timer handler which periodically retrieves the data from the container. you would need to make the access to the container thread-safe by a critical section, a mutex or a lock.

Sara
0
 

Author Comment

by:novreisb
ID: 39985790
Thanks Sara, you give me good ideas
Anyway as I am not english native pheraps  I  was not clear enough. The two usercontrols are children of a midcontainer and I do not need to return data from the "batch user control" to the user control  that is receiving emails. The datagrid I was talking is inside the batch control and I must work on this datagrid after the process finishes. As I like productivity, during the Batch Process I would like to go to the receiving mails control and work here, but I was not able to do that!
This is not going to change your advise, I think,  but it simplifies the problem. I will put the "batch process" on a thread, as you said,  and see if  it releases it to work on the mail control!
0
 
LVL 34

Accepted Solution

by:
sarabande earned 500 total points
ID: 39985972
if the window of the "batch user control" belongs to a different process it would be valid.

a window controlled by a thread which belongs to the same process as another active window, is not a recommendable solution. the problem is that the thread would need an own message pump which would freeze while reading emails. so you would need a further thread which retrieves mails while the ui thread runs the message pump. windows also doesn't like this way. the new window owned by the thread must create a new "context" such that both the message queues of your process could be properly separated.

I would recommend to choose one of two other ways. one is to integrate the control into the foreground application (thread). that way the "batch" could be a pure worker thread and you could exchange the new mails by messages as I described above. the other is to have a second program (process) for the batch control and emails and use p2p-communication (program-to-program) to control the second program by the first one. you could do that by windows messages or shared memory or network calls (client-server).

Sara
0
 

Author Closing Comment

by:novreisb
ID: 39986200
Thanks very much Sara. I will try those suggestions!
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
There are many software programs on offer that will claim to magically speed up your computer. The best advice I can give you is to avoid them like the plague, because they will often cause far more problems than they solve. Try some of these "do it…
The viewer will learn how to create multiple layers to apply various filters and how to delete areas from each layer’s filter.
XMind Plus helps organize all details/aspects of any project from large to small in an orderly and concise manner. If you are working on a complex project, use this micro tutorial to show you how to make a basic flow chart. The software is free when…

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question