Solved

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

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

Forrester Webinar: xMatters Delivers 261% ROI

Guest speaker Dean Davison, Forrester Principal Consultant, explains how a Fortune 500 communication company using xMatters found these results: Achieved a 261% ROI, Experienced $753,280 in net present value benefits over 3 years and Reduced MTTR by 91% for tier 1 incidents.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
software inventory tools 3 61
asp.net figure out error 3 20
Mutiple Folder view (5 Folder view) 3 48
SSIS GUID Variable 2 31
This article describes how to use the timestamp of existing data in a database to allow Tableau to calculate the prior work day instead of relying on case statements or if statements to calculate the days of the week.
This guide will walk you through the essential considerations and tech stack for building scalable websites. Know how to grow your business the smart way!
The viewer will learn common shortcuts with easy ways to remember them. The viewer will then learn where to find all of the keyboard shortcuts, how to create/change them, and how to speed up their workflow.
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.

735 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