Click here to Skip to main content
15,900,511 members
Home / Discussions / Design and Architecture
   

Design and Architecture

 
GeneralRe: Never use pure built in types Pin
jschell16-Dec-14 12:37
jschell16-Dec-14 12:37 
AnswerRe: Never use pure built in types Pin
jschell12-Dec-14 12:26
jschell12-Dec-14 12:26 
GeneralRe: Never use pure built in types Pin
D4rkTrick21-Dec-14 8:17
professionalD4rkTrick21-Dec-14 8:17 
QuestionHow to avoid backend stored procedures Pin
nstk8-Dec-14 21:24
nstk8-Dec-14 21:24 
JokeRe: How to avoid backend stored procedures Pin
Brady Kelly12-Dec-14 5:52
Brady Kelly12-Dec-14 5:52 
AnswerRe: How to avoid backend stored procedures Pin
Eddy Vluggen12-Dec-14 7:27
professionalEddy Vluggen12-Dec-14 7:27 
AnswerRe: How to avoid backend stored procedures Pin
Dominic Burford23-Dec-14 1:35
professionalDominic Burford23-Dec-14 1:35 
QuestionRearchitecting BackgroundWorker based to Task based? Pin
Matt T Heffron17-Nov-14 12:49
professionalMatt T Heffron17-Nov-14 12:49 
I'm trying to figure out to use System.Threading.Tasks.Task asynchronicity in conjunction with waiting for Win32 HANDLE triggering.

Summary:
I'm interfacing with an unmanaged DLL which communicates with a data collection device. ([DllImport("xxx.dll", CallingConvention = CallingConvention.Cdecl, ...] on each unsafe method.)
One of the methods will acquire N data records asynchronously into a user supplied buffer. Specifically, it "spawns the data read on a background thread", and returns a HANDLE to wait on for completion.
There is an additional method which will provide a different HANDLE that can be waited on for notification that some of the data is ready (every M (M <= N) data records).

The UI should display the latest data at EITHER the interval or completion notifications.
Further, all of the data is captured in a BlockingCollection so the captured data can be written to files asynchronously.

For an initial feasibility effort I have 3 BackgroundWorker instances for these.
The intent was learning how the interfacing with the device works, so no design!
This is coding by accretion == throw away!

The data collection worker calls a method in a class that wraps the DLL. The wrapper method calls the above DLL methods and gets the 2 HANDLEs. They are associated with instances of AutoResetEvent which are waited on with WaitHandle.WaitAny(). The wrapper method loops until completion, passing each data record to a delegate that was provided.
The delegate enqueues the data record in the BlockingCollection and, conditionally, updates a pointer to the next data to display (using Interlocked.Exchange()) and Set()s a ManualResetEvent to indicate that there is something to display.

The live display worker is just a simple loop that Reset()s the ManualResetEvent (set above), WaitOne() on it, and again using Interlocked.Exchange(), gets the pointer to the data to display and displays it.

The file save worker is a foreach over the BlockingCollection.GetConsumingEnumerable(), uses the ReportProgress() to have a progress bar updated and writes each data record to its file.

This will be redesigned for the production use.
This all seems way too complicated.
BackgroundWorker doesn't seem like the correct strategy.
It seems that using System.Threading.Tasks.Task ought to be a cleaner solution.
(I haven't needed to use System.Threading.Tasks.Task on any project before, so no real experience... I have read the blog entries by Stephen Cleary.)

Any suggestions on restructuring away from "quick-n-dirty" to "clean and maintainable"?
Or pointers to how to think with System.Threading.Tasks.Task?

Thanks.
A positive attitude may not solve every problem, but it will annoy enough people to be worth the effort.

AnswerRe: Rearchitecting BackgroundWorker based to Task based? Pin
Richard Deeming18-Nov-14 2:45
mveRichard Deeming18-Nov-14 2:45 
AnswerRe: Rearchitecting BackgroundWorker based to Task based? Pin
Gerry Schmitz18-Nov-14 7:00
mveGerry Schmitz18-Nov-14 7:00 
QuestionRemote Desktop Connection Pin
Non Sequitur11-Nov-14 3:43
Non Sequitur11-Nov-14 3:43 
SuggestionRe: Remote Desktop Connection Pin
ZurdoDev11-Nov-14 5:27
professionalZurdoDev11-Nov-14 5:27 
AnswerRe: Remote Desktop Connection Pin
Pete O'Hanlon11-Nov-14 5:57
mvePete O'Hanlon11-Nov-14 5:57 
QuestionWhat is an architect for? Pin
Member 448708318-Oct-14 10:19
Member 448708318-Oct-14 10:19 
JokeRe: What is an architect for? Pin
Vivi Chellappa18-Oct-14 18:43
professionalVivi Chellappa18-Oct-14 18:43 
AnswerRe: What is an architect for? Pin
kimpetwangi25-Oct-14 17:12
kimpetwangi25-Oct-14 17:12 
AnswerRe: What is an architect for? Pin
Richard MacCutchan18-Oct-14 21:22
mveRichard MacCutchan18-Oct-14 21:22 
GeneralRe: What is an architect for? Pin
Member 448708318-Oct-14 21:59
Member 448708318-Oct-14 21:59 
GeneralRe: What is an architect for? Pin
Richard MacCutchan18-Oct-14 22:08
mveRichard MacCutchan18-Oct-14 22:08 
AnswerRe: What is an architect for? Pin
Eddy Vluggen19-Oct-14 3:50
professionalEddy Vluggen19-Oct-14 3:50 
GeneralRe: What is an architect for? Pin
Member 448708319-Oct-14 11:26
Member 448708319-Oct-14 11:26 
GeneralRe: What is an architect for? Pin
Eddy Vluggen20-Oct-14 1:44
professionalEddy Vluggen20-Oct-14 1:44 
AnswerRe: What is an architect for? Pin
Mycroft Holmes19-Oct-14 12:48
professionalMycroft Holmes19-Oct-14 12:48 
AnswerRe: What is an architect for? Pin
Dominic Burford20-Oct-14 6:30
professionalDominic Burford20-Oct-14 6:30 
QuestionArchietecture design Pin
ibnipun109-Oct-14 21:10
ibnipun109-Oct-14 21:10 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.