|
Hi Keith,
KeithF wrote: Am I on the right tracks here?
yes, well, maybe. I did not study your code in much detail, I do see a state-machine-like approach, which could be fine; however I have issues in several aspects:
1. I'm not sure I know enough about your "protocol" to judge the approach. As I said, what you need as an implementation heavily depends on your protocol.
e.g. what should happen when an unexpected response is received (say you send an ENQ and then receive an ETX where it "should" have been an ACK)
2. I didn't see your actual transmit and receive operations; is your receiver operating asynchronously (i.e. using a completion event)? or blocking (i.e. just read-and-wait-till-done)?
3. You seem to somewhat merge, then split, inbound and outbound messages; not sure why.
4. Whatever the goals and needs, I'm pretty sure my code would look quite differently, but that is a matter of style. In particular I'm not fond of methods that need data, don't get it as a parameter, and then go fetch it somehow (as your SendMsg-MessageToSend pair is doing).
Here is what I might consider doing if your protocol is somewhat close to what I think you intend:
- I would opt for (pseudo)synchronous transmit and asynchronous receive;
- so I would transmit using SP.Write() and act as if the data is gone instantly (if necessary just include a sleep period that corresponds to the normal transmission time, probably not necessary at all);
- and I would not read except inside the DataReceived handler.
- that would halve the number of states I need, as each state typically would be an "awaiting" state, say "waiting for ACK0";
DataReceived should check the next inbound message;
if it is an ACK0, send a new message (synchronously!), adapt the state (say "waiting for "ACK1"), and return;
if it isn't, send a new message ("aborting"), set state="IDLE" (=waiting for anything), and return;
- so that boils down to a big switch inside DataReceived, switching to the current state (what am I expecting?), then looking at what actually was received, react (probably by sending something) and adapt the state, so the next DataReceived switch will go to another case.
That would work for simple cases; it would not cope well with slow transmission conditions: if you want overlaps (comparable to overlapped file I/O in Windows) or if your state actions are too large to handle in DataReceived itself, you may need a more complex scheme, maybe an input queue, etc.
Hope this helps. But once again, as I said, it all depends on what you need. It would not make sense to create a 1000 LOC class for a thermometer that sends one or two strings per second.
|
|
|
|
|
Dear developers,
Does someone knows how can I iterate all open child forms from the mdi parent
And for each form save the report to one excel file?
|
|
|
|
|
Hope thsi will help you
foreach (Form frm in Application.OpenForms)
{
}
I Love T-SQL
"VB.NET is developed with C#.NET"
If my post helps you kindly save my time by voting my post.
|
|
|
|
|
hi,
the problem i accessing the reports from each form and saving it to one workbook
is it possible?
foreach(Form frm in this.MdiChildren) {
saving each report to a workbook
}
|
|
|
|
|
|
How To Convert The English To Gujarati in The Asp.net With C#
|
|
|
|
|
Language translation, even between similar languages (which Gujarati and English aren't) is not a facile task.I suggest you use an online service like google translate, or find a commercial product that does this. Even so, no translation software is 100% accurate.
|
|
|
|
|
This[^] is a fairly complete guide on this topic.
Its always easier to plan localization in advance (before development starts).
If the site already exists, it will be harder to implement localization.
|
|
|
|
|
|
Hi,
i work with asp.net c#, how can we insert multiple lines text (label) in a single row of datagridview?
Thank you verry mutch.
|
|
|
|
|
Probably by asking in the ASP.NET forum!
Unrequited desire is character building. OriginalGriff
I'm sitting here giving you a standing ovation - Len Goodman
|
|
|
|
|
|
Hey All,
Just d/l your checkers game...http://www.codeproject.com/KB/game/DirectXBoardGameEngine.aspx[^]
However when I open it I am asked to convert it. When I try to build the game it says 'TypeLoadException was unhandled'
Method 'Initialize' in type 'Bornander.Games.Checkers.Direct3D.CheckersModelRepository' from assembly 'Bornander Games Checkers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' does not have an implementation.
Please advise?
Thanks in advance
|
|
|
|
|
You haven't downloaded my code here, you've downloaded Frederik Bornander's code from that article. Funnily enough, there's a forum at the bottom of the article (all the articles have forums) where you can ask THE ORIGINAL AUTHOR about their code. After all, they are the experts in their code and they are best placed to answer your questions.
|
|
|
|
|
|
MSDN wrote: The ?? operator is called the null-coalescing operator and is used to define a default value for a nullable value types as well as reference types. It returns the left-hand operand if it is not null; otherwise it returns the right operand.
|
|
|
|
|
Thanks.
|
|
|
|
|
The ?? is known as the null coalescing operator. That's a fancy dance way of saying that it tests to see if the left hand side is null, and if it is, it uses the right hand side. What this is doing, in your example, is evaluate items to see if it's null, and if it is, it assigns a new list to it and returns that. In practical terms, this is the same as doing this:
if (items == null)
items = new List<Item>();
return items I have missed the addition of the Item instances to the array to simplify this example, but you should get the idea from it.
[Edit]The OP deleted the original message. It was:
public class Item
{
public double X { get; set; }
public double Y { get; set; }
public string Name { get; set; }
public string Color { get; set; }
}
public class ItemsFactory
{
private List items;
public IEnumerable Items
{
get
{
return items ?? (items = new List<item>()
{
new Item { Name = "One", X = 33, Y = 25, Color = "Red" }, new
new Item { Name = "Two", X = 44, Y = 99, Color"Blue" }
});
}
}
}
modified 14-Nov-11 6:11am.
|
|
|
|
|
You put it much better than MSDN!
It’s not because things are difficult that we do not dare, it’s because we do not dare that things are difficult. ~Seneca
|
|
|
|
|
Thanks Annie. That's because, unlike MSDN, I'm trying to educate.
|
|
|
|
|
Thanks
|
|
|
|
|
Why did you delete your question? Don't do that.
"I love deadlines. I like the whooshing sound they make as they fly by." (DNA)
|
|
|
|
|
I have edited my answer to show what the OP asked.
|
|
|
|
|
Dear developers.
I developed a simple app that has a report viewer which connects to SQL server 2008.
i need to deploy the application to a terminal where all users can open it using a Shortcut to the exe trough Citrix.
My last app was in vb there where no problems there I just copied the exe file to the terminal and created the shortcut and everything worked fine.
Now I am using c# and the exe file trough an exception that the report viewer not found.
I tried the publishing it using ClickOnce and it is working.
The Q is can I only use the exe file and not publish the app? Because the shortcut targets only the exe file
Tanks,
Pniel
|
|
|
|
|
I would like to know if the following code is written ok or is there a better way? If there is a better way, can you explain and/or point me to a reference I can use? Is the linq writing from one datacontext object to some data fields ok? Also is the try catch adequate?
I do know the code works since I stepped through the code.
I am asking the question is this is my first time working with linq to sql in a C# 2010 application and I am the only programmer at my company.
<pre> protected void Ready_Data(Attes att, AtsDataContext attDataContext)
{
try {
var results = from s in attDataContext.Attes_Schedules
where s.Pay_Month == att.Pay_Month_Date
select new
{
PayDate = s.Pay_Month,
CurCStopDate = s.Current_C_Stop_Date,
PriorCStopDate = s.Prior_C_Stop_Date,
RptsReceviedMonth = s.Rpts_Rec_Month,
};
foreach (var r in results)
{
att.Pay_Month_Date = r.PayDate;
att.Current_C_Stop_Date = r.CurCStopDate;
att.Prior_C_Stop_Date = r.PriorCStopDate;
att.C_Rpts_Rec_Date = r.RptsReceviedMonth;
}
}
catch (Exception ex)
{
lblErrorMsg.Text = "Attes Page Processing problem";
lblErrorMsg.Visible = true;
hold_Exception = ex;
}
}</pre>
|
|
|
|