Solved

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

Posted on 2014-04-07
4
852 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
  • 2
  • 2
4 Comments
 
LVL 32

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 32

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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

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…
A high-level exploration of how our ever-increasing access to information has changed the way we do our jobs.
Video by: Tony
This video teaches viewers how to export a project from Adobe Premiere Pro and the various file types involved.
Viewers will learn how to use the Hootsuite Dashboard.

759 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now