Solved

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

Posted on 2014-04-07
4
859 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 33

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 33

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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Suggested Solutions

If your app took Google’s lash recently, here are the 5 most likely reasons.
Today, still in the boom of Apple, PC's and products, nearly 50% of the computer users use Windows as graphical operating systems. If you are among those users who love windows, but are grappling to keep the system's hard drive optimized, then you s…
This video demonstrates how to use each tool, their shortcuts, where and when to use them, and how to use the keyboard to improve workflow.
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…

786 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