'Producer Consumer' Design Pattern Using Queues?

Jul 23, 2009

I'm trying to replicate a design pattern used in a graphical programming language called LabVIEW. One thread produces commands, and another thread, or series of threads, consumes the commands.This is very similar to using Queues in VB...but there doesn't seem to be an easy way to start the consumer thread when new items are added to the queue.

Here is what I would like to accomplish, please let me know if there is a straightforward way to accomplish this with out of box .Net functionality.1) Start the Consumer Thread...it sits idle, waiting for some new commands to appear in its Queue.2) Producer places a few commands into the Queue. Example: "Home X Axis", "Home Y Axis", "Initialize Pump", "Display Ready Message"3) Consumer thread 'wakes up' at seeing the new commands, then performs the 4 tasks specified in 2.4) Consumer thread goes 'idle' again, and simply waits for new commands to appear in the Queue.

Process can continue on and on forever. The main problem I see with Queues is that there is no 'Wait for Something to Appear in Queue then Retrieve it" functionality. I don't want to use a perpetual loop to keep checking ever n milliseconds.

View 1 Replies


ADVERTISEMENT

.NET Multi-threaded Variable Access - (GUI, Controller, Producer, Consumer)

Jul 25, 2009

I have an application with 4 threads. (GUI, Controller, Producer, Consumer) The GUI is self-explanatory. The controller starts the producer and consumer threads after some intial setup. The producer creates items and places them in a free slot in a "ring buffer". The consumer takes items from the "ring buffer" and writes them to disk. The producer creates items at a much higher rate than the consumer. The consumer is IO heavy and IO bound. Currently I am checking a variable in each ring buffer slot to determine if it can be written to.

if Slot.Free then
Write Slot.Data To Disk
end if

I am not using lock/synclock instead I'm just reading / writing the value of the slot's "free" variable. I don't believe that is correct even though it is a volatile read/write. Is there a better method to read/write this variable? The variable is of type "integer" and is either 0 or 1.

View 5 Replies

Looking For Design Pattern / For Each Instead Of For With Index

Jun 4, 2012

Using VB.Net, I'm looking for best practices in dealing with the following idiom:[code]What I really want is something VB.Net doesn't offer -- additional and simultaneous iterators on For Each statements.[code]I'm interested in both Linq and non-Linq recommendations, comments about Copy method design, comparisions to C# or other languages.

View 3 Replies

.net - Design Pattern For TypeOf Subclass?

Mar 4, 2012

I am working on a parser for a serial data protocol. I have an overarching Packet class, a couple sub-classes such as CommandPacket and StatusPacket, and then a few sub-classes of each of those:

[Code]..

While I don't think it is entirely relelvant to the discussion, I am doing this in VB.NET. There is also a similar (but not quite the same) question posted here: Java - subclass validation design pattern

View 2 Replies

C# - Design Pattern For Custom Events In .NET?

Feb 21, 2010

What is the proper design pattern for custom events in .NET (VB or C#).

I am refering to custom events, where in you override the AddHandler, RemoveHander, and RaiseEvent methods.

View 1 Replies

Design Pattern For Database Interaction?

Mar 12, 2012

I've been studying design patterns off-and-on now for a project I've recently been working on. I've been fortunate with this last one not to have to work with databases, but will soon have an opportunity.

View 8 Replies

C# - Anonymous Method Alternative For Design Pattern?

Apr 18, 2012

With C# anonymous delegates, we can avoid declaration of extra method, I know in VB.NET they're not available, but is there a design pattern that I can use so that I can avoid writing an extra method each time? I need it for SPSecurity.RunWithElevatedPrivileges which will be used a lot of times in our code.

[Code]...

View 1 Replies

C# - Design Pattern For Dealing With Syncing Variables?

Jan 30, 2012

Suppose I have two events:

Public Sub Control1Updated() Handles control1.TextChanged
control2.Text = SomeFunction(control1.Text)
End Sub

[code]....

Basically the pairs of {control1.Text, control2.Text} and {control2.Text, control1.Text} should be the same. If control1.Text is changed to let's say "a" then control2.Text is ALWAYS "b". If control2.Text is changed to "b" then control1.Text is ALWAYS "a". How do I achieve this with events without going into an infinite loop? [the best I can think of is to make a check if the other control.Text is already the desired value].

View 1 Replies

What Are The Features Of The Controller Class In The MVC Design Pattern

Aug 13, 2009

In the MVC design pattern we must use a controller(s) classes.

What are the fucntions (features) of the controller apart from handling communication bewteen Model and View?e.eg; can we include input validation code in the controller?

View 4 Replies

What Type Of Code Should Put In The Controller In The MVC Design Pattern

Jul 7, 2009

In teh MVC design pattern, Controller is strongly related to the view (GUI). IN my application i need to generated a new BrandID, i used stored procedure to retreive the highest BrandID from teh DB (The model calls the stored procedure and sends the retreival value to the Controller), then in the controller increments the BrandID by "1" to create a new brand ID. SInce, controller is strogly related to "view", should i include this "brandID increment" part in teh controller or in the model classes?

View 3 Replies

C# - Which Design Pattern For Activity Logging (Audit Trailing)

Jun 15, 2012

I have a winform which allows people to edit data from a database, to simplify things assume there is a Customer table in database with 3 fields - Name, City, Country. Through winform(s) people can Add/Edit/Delete customers.For each of these actions we need to save:

What the field names are (Name,City,Country in this case)What the field values were before they were modified What the field values are after they are modified.If the action is Add or Delete then 2 and 3 will be the same.I have already implemented this using XMLSerialisation (but not using any of the design patterns) and my XML output looks like this.

<?xml version="1.0" encoding="utf-8"?>
<ActivityItem xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<UserID>26</UserID>
<FormTitle>frmCustomer</FormTitle>

[code]....

The solution can handle different areas of the system with different number of fields (i.e the same thing works when you are modifying Products for instance).is there a well defined design pattern to deal with this kind of behavior?

View 2 Replies

Lifetime Of Multiple Instances Of An Object / Design Pattern?

Sep 5, 2009

having difficulty with understanding object lifetime / instantiation.I have a windows from with a datagridview and a panel. The datagridview has a checkbox column and a list of names which is populated from a database.The panel has a few text boxes (e.g. name, age, favourite sports team) and a 'save changes' button.

The idea is that when the user selects a person in the datagridview by checking the appropriate checkbox then the panel shows the relevant data for that person (name, age, fav sports team) by pulling the data from a database. If the user would like to update the person's details they can do so by typing in the textboxes and then clicking the 'save changes' button. All quite simple so far.

The way I have designed this is to have a 'panel' class and to create an instance when the user checks a checkbox.(NB - the reason I have created a 'panel' class is that I intend to replicate the datagridview and panel on other tabpages within my form and thought it would be useful to have a generic 'panel' class that I could re-use.)

My code looks a bit like this:

If CheckBoxClicked Then
Dim UpdatePanel As New UpdatePanel(MyForm.NameTextBox, MyForm.AgeTextBox, MyForm.FavSportTeamTextBox, MyForm.SaveButton)
UpdatePanel.GetData()
...

When the user clicks the SaveButton the data is updated to the database and I have a display message (simple textbox) which says "Update successful" and displays for 5 seconds before hiding itself.

Here is the problem:Suppose a user checks a checkbox, reviews the data and does not make any changes, and then checks another checkbox and decides to update the data by clicking the 'save changes' button. What happens is that the "Update successful" message is displayed twice.

I think this is because every time the user checks a checkbox an instance of UpdatePanel is created. If a I select five different people using the checkboxes and then hit 'save changes' I get five "Update successful" messages.

I am not sure how to overcome this. It feels like each time a checkbox is clicked I need to check if an instance of UpdatePanel exists and then destroy it. I tried using UpdatePanel = Nothing and also investigated IDisposable and GC.Collect() but with no luck.

[code]....

View 1 Replies

Asp.net - Refactor To Design Pattern: Displaying/hiding Different Combinations Of Controls Based On State?

May 26, 2009

Assume you have controls A, B, C, D and E all with a Visibility property. You also have states 1,2,3,4,5 and 6 in which various combinations of your controls would be displayed. Currently this is being handled by switch statements for each state: i.e.

Select Case PageState
case "1"
a.visible = false
b.visible = true

[code]....

As you can imagine, this becomes a pain as every state needs a show/hide statement for each control. How can I refactor this so that adding controls and/or states becomes trivial?My first instinct is to extend the control and add a collection of states that it should display for but this sounds like overkill.

Edit:I was deliberately vague in my question in case this has other implications. In my current instance the "controls" in question are ASP Panels. Does that change anything?

View 4 Replies

C# - Get A Code Template/design Pattern Can Use When Reacting To Mouse Clicks Or Button Presses?

May 3, 2011

One of the problems that I constantly see with Winforms applications is that the GUI thread is stuck while a long-running task is running or just plain stops refreshing (yes, I know - needs threading). Is there a code template/design pattern I can use when reacting to mouse clicks or button presses? Should there be a processing thread always running in the GUI app? Basically, how do I write a great Winforms Application that is easy to maintain and doesn't have any quirky refresh bugs?

View 4 Replies

Access A Rails 3 REST-ful Web Service Using A .NET Consumer?

Sep 10, 2010

What is the best way to access a Rails 3 REST-ful web service, developed using standard Active Resource techniques including HTTP authentication over SSL, from a VB.NET consumer?Consumer can be .NET 4.0 if that is necessary.Are there any .NET libraries yet that can bridge the gap?

I have already come across links like this [URL]..web-services/), which use Linq.XML or XML.XPath to parse responses and generate post data for REST-ful web services. I have in fact coded a system similar to the one at that link, except for a different geo-coding provider and using XPath instead of Linq.

View 2 Replies

How To Use Queues In .net

Aug 1, 2009

how to use queues in vb.net. i want to make it like when ever i add new string into the queues, it will compare the value inside the queues first b4 add into the queues and if compare half way through, there is same value. the value will not add into the queues.

View 13 Replies

.net - Using Multicast Queues In System.Messaging And MSMQ 3.0?

Dec 21, 2011

I am trying to use MessageQueues to notify users of an application of data changes using the Multicast feature, but can't get it to work : the workstation that sends the message does receive it, but none of the other running workstations seem to catch the sent message.Sending messages is done as follows :

Dim sendQueue As New Messaging.MessageQueue("FormatName:MULTICAST=234.1.1.1:8001")
Dim message As New Messaging.Message("message body...")
sendQueue.Send(message)

And receiving them :

Dim receiveQueue As New Messaging.MessageQueue(".private$myQ")
receiveQueue.MulticastAddress = "234.1.1.1:8001"
receiveQueue.BeginReceive()

[code]....

So I'm obviously missing something, and I can't seem to find any good ressources on multicasting with MSMQ 3.0 in .NET.Also, what is not clear is wether I should use a local queue per workstation, or one single remote queue on a server to multicast messages ? And does using the receive method on multicast messages purge them from the queue ?On a side note, all workstations are on the same subnet, and all have MSMQ 3.0 installed.

Despite what the Queue properties dialog says, permissions are NOT totally ignored on unauthenticated queues, at least when using multicasting. If you want your queue to receive multicast messages, it must give to 'ANONYMOUS_LOGON' the right to 'Send messages'. Otherwise, multicast messages are just discarded without any notice in event logs or whatsoever (unless I missed something).

On Win7 stations (XP stations seem to do fine, which is what pointed me to the actual problem), queues created through code do not have such permissions, and hence must be manually set after creating the queue :

Dim msgQ = Messaging.MessageQueue.Create(queueName)
msgQ.SetPermissions("ANONYMOUS LOGON",
Messaging.MessageQueueAccessRights.WriteMessage)

It would seem that internally, MSMQ uses that account to write multicast messages to unauthenticated queues.

View 1 Replies

GetPrivateQueuesByMachine - Get A List Of Queues From A Remote Machine

Dec 4, 2009

I'm using the 2.0 framework to get a list of queues from a remote machine. Sometimes the machine has a firewall and then the user has to wait 80 seconds or so before an exception is thrown stating that the machine is unavailable. Questions: Is there any way that I can set/change the timeout for GetPrivateQueues ByMachine? Is there any other method I can call before running GetPrivateQueuesByMachine to see whether the machine is responding? One that has configurable timeout, Any other solution?

View 1 Replies

Inheritance And Variety Of Data Structures Including Queues, Lists, Arrays, Or Stacks In A Windows Forms Application

Jun 27, 2012

I'd like to give a homework assignment to a person learning VB.NET. I'd like it to use basic inheritance and a variety of data structures including queues, lists, arrays, or stacks in a windows forms application. I was thinking of a pizza-ordering application. This would allow them to utilize some basic inheritance and practice using .NET UI elements.

View 2 Replies

Css - Design A Webpage In Asp.net Design View Which Support Multi Resolution?

Nov 26, 2010

I have created my webpage in asp.net in 1024*768 resolution, my problem was that when i change my monitor resolution then the controls in my webpage will be displayed in unmanaged manner .

How to arrange items in my webpage which support multiple resolution ...

Whatever the resolution of my monitor the controls in my webpage will display as it is as managed in 1024*768 reolution !

View 1 Replies

Form Design - Cannot Expand Vertically In Design View

Jun 27, 2011

I seem to have reached a limit on the size of the form. I cannot make the form longer and I need to add more fields. Is there a limit on how many fields can be included in a form?

View 1 Replies

C# - Design Reference And Object Oriented Design Of A CRM

May 25, 2011

I searched codeplex and google. I have found so many such as tustena but unfortunately they are not domain driven based and in these solutions I could not find a good modelling documents or references. i am a newbie in CRM but I am sensetive to design it with solid object-oriented fundamentals. Any reference or open source solution especifically for CRM design and implementaion in .NET? Cheers

View 1 Replies

.net - What Is This Pattern Called

Sep 8, 2009

Private someSub()
If someBoolean = True Then Exit Sub
' do some great work because someBoolean is False
End Sub

I know there is a name for this. The idea is to check something and if it isn't what you want then you stop code processing. I thought it was called "escape pattern", but Google isn't confirming that name.

View 4 Replies

Asp.net - When Should The Factory Pattern Be Used

Jun 22, 2009

when should a trigger in your head go off signifying "Aha! I should use the factory pattern here!"? I find these moments will occur with many other design patterns, but never do I stop myself and think about this pattern.

View 6 Replies

How To Find A Pattern

Nov 9, 2009

i got this var: dim myvar as string

[Code]....

(Someone know how insert this ==>"<== into a var ? In PHP i use " ex: myvar = "Console.Writeline("hii")" but didnt work in vb net, how do it ?)

View 4 Replies

How To Use MVC Pattern Efficient

Aug 9, 2009

How to use MVC Pattern efficient?

View 8 Replies

Looking For Pattern In A String?

Mar 21, 2012

How would I remove an alpha-numeric sub string in a string that meets these rules:

J111DD
L###LL
l = Leter
# = Number

View 1 Replies

Mvc - Using The Repository Pattern

Feb 23, 2011

I am using the Entity Framework with POCO's generated using the T4 Templates. I have the generated classes in a separate assembly. Ok, so a very simple example: I have a Category entity in the model which has SubCategories (1-Many with SubCategory). When I use the following code, I get The ObjectContext instance has been disposed and can no longer be used for operations that require a connection. [Code]

View 2 Replies

Singleton Pattern In Vb?

Jul 23, 2010

I am normally a c# programmer but am now working in VB for this one project when I use to set up a singleton class I would follow the Jon Skeet model

public sealed class Singleton
{
static Singleton instance = null;
static readonly object padlock = new object();

[code]....

I get StackTracker.Instance.Instance and it keeps going, while it is not the end of the world it looks bad.is there a way in VB to hide the second instance so the user can not recursively call Instance?

View 1 Replies

C# - When Are Predicates Appropriate And What Is The Best Pattern For Usage

Jan 11, 2011

When are predicates appropriate and what is the best pattern for usage? What are the advantages of predicates? It seems to me like most cases where a predicate can be employed a tight loop would accomplish the same functionality?

View 3 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved