|
Hi,
IMO you need extra threads to do it properly.
Three of them for a process that generates output at stdout and stderr, where you want to get that output in a timely fashion, and keep full control over the process:
- one where you launch the Process and can wait for exit, sleep and check/kill, or sleep and test for exit in a loop; this could be your main thread;
- a background one to read and process what is available on stdout (not using ReadToEnd of course)
- a background one to read and process what is available on stderr (not using ReadToEnd of course)
BTW: when the first thread detects the process is done, I give it one more second before I tell the other two threads to call it quits.
Unfortunately the MSDN examples are way too simple. Having no extra threads implies you can't intertwine stdout and stderr output, and you are unlikely to get any output until either the process is done, or a lot of output has been generated.
BTW: if you were to try it on .NET 1.0 or 1.1 it would be harder, since those didn't handle things well. I have not been able to pinpoint the exact problem a that time, but I have abandoned them long ago anyway.
Luc Pattyn [Forum Guidelines] [My Articles]
- before you ask a question here, search CodeProject, then Google
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get
- use the code block button (PRE tags) to preserve formatting when showing multi-line code snippets
modified on Thursday, March 26, 2009 11:40 AM
|
|
|
|
|
Hi Luc,
thanks for your quick reply. Unfortunately I have a problem with your BTW
The reason is that I have to execute a lot of commands one after the other and cannot wait a second for being sure, that the streams are empty (with 1000 files it would take 17 minutes just waiting).
But nevertheless to 'move' the output to separate threads sounds good. The only thing what I then still not have is an option to check if the process output/error stream has been terminated. This would be a perfect solution/trigger to go on with the normal program. Unfortunately (again) the options from the process class are not sufficient to do this with asynchronous outputs (at least what I found).
Again Thanks a lot! In worst case I have to check for a good 'waiting' time (maybe 100ms are enough) and parallelise something else to come back to acceptable values.
Brgds,
Michael
|
|
|
|
|
Hi Michael,
some more remarks and ideas:
1.
if the process outputs to stdout(stderr) without explicitly closing it, the stream will remain open for as long as the process lasts, so there is no way to predict the end of the stream anyway.
2.
if you are dealing with several commands/processes, then you can reuse the stdout/stderr handling threads.
3.
When I said 1 second, you can modify that time span and make it suit your situation. I would not hope and get it below 0.1 second though.
4.
and you don't need to waste 1 second every time, you could simply create a "phase shift", i.e. launch the next process immediately while still listening to the output of the previous one for one second, and then start listening to the next process (which could already be running for 1 second by then).
5.
You might, depends on the circumstances, create a batch file that executes all 1000 necessary commands, and launch that as a single process (which obviously would spawn 1000 processes one after another). Doing so you only need a single 1 second wait, however you would get all output in one large streams. Obviously you could create the batch file by hand or by program.
Luc Pattyn [Forum Guidelines] [My Articles]
- before you ask a question here, search CodeProject, then Google
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get
- use the code block button (PRE tags) to preserve formatting when showing multi-line code snippets
|
|
|
|
|
Hi Luc,
thank you very much for your suggestions. Sometimes the easy solutions do not come into my mind when thinking too hard about a problem
A little bit code refactoring and i am on my way again.
thank you very much again and have a nice weekend!
Brgds,
Michael
|
|
|
|
|
you're welcome.
Luc Pattyn [Forum Guidelines] [My Articles]
- before you ask a question here, search CodeProject, then Google
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get
- use the code block button (PRE tags) to preserve formatting when showing multi-line code snippets
|
|
|
|
|
I have an app where I display a list of link buttons (determined by variable number or records returned from a db). I create the link buttons dynamically but the click/command event(s) do not fire when the button is selected.
Also, this is in an <asp:panel xmlns:asp="#unknown"> which is in the content section of a master page.
<br />
protected void Page_Load(object sender, EventArgs e)<br />
{<br />
if (!Page.IsPostBack)<br />
{<br />
}<br />
BuildLinkButtons();<br />
}<br />
<br />
protected void BuildLinkButtons()<br />
{<br />
Label lblNew = new Label();<br />
<br />
lblNew.ID = "weekLabel";<br />
lblNew.Text = "Select A Week:";<br />
lblNew.Font.Bold = true;<br />
weekPanel.Controls.AddAt(0, lblNew);<br />
weekPanel.Controls.AddAt(1, new LiteralControl(" "));<br />
<br />
int iPos = 2;
for (int i = 1; i < 10; i++)
{
LinkButton lnkBtn = new LinkButton();
lnkBtn.ID = "lnk1:" + i.ToString();
lnkBtn.Text = i.ToString();
lnkBtn.Click += new EventHandler(lnkBtn_Click);
lnkBtn.CommandName = i.ToString();
lnkBtn.Command += new CommandEventHandler(lnkBtn_Command);
weekPanel.Controls.AddAt(iPos++, lnkBtn);
weekPanel.Controls.AddAt(iPos++, new LiteralControl(" "));
}
}
void lnkBtn_Command(object sender, CommandEventArgs e)
{
// do some stuff here
}
void lnkBtn_Click(object sender, EventArgs e)
{
// do some stuff here
}
|
|
|
|
|
hello.. actually the problen is that i have added an msaccess database to my project and have buitl about 10 queries and contains 3 tables in it.
now i want to add a new table or modify an existing table in the database and when i modify the tables its not effecting in the data-sources in the project..what is the way to edit the database after adding it to the project without loosing the queries built in the dataset designer.. thans...
|
|
|
|
|
max.4u
Please Please take your time and explain things clearly.
Vuyiswa Maseko,
Few companies that installed computers to reduce the employment of clerks have realized their expectations.... They now need more and more expensive clerks even though they call them "Developers" or "Programmers."
C#/VB.NET/ASP.NET/SQL7/2000/2005/2008
http://www.vuyiswamaseko.tiyaneProperties.co.za
vuyiswa@its.co.za
www.ITS.co.za
|
|
|
|
|
sure.. actually mine is c# project.. and it has database of ms access by name test.mdb
test.mdb has a table named user_data
it has coloums id,pass.
this database is added to the project.
then i need to modify the table coloums like adding the new coloums.
when i add the new coloums its change is not taking effect in my project...
|
|
|
|
|
If i understand you correctly you went to Access Db and Opened it and change or added new columns and when you say it does not reflect in your project what do you mean ? please explain that part.
Vuyiswa Maseko,
Few companies that installed computers to reduce the employment of clerks have realized their expectations.... They now need more and more expensive clerks even though they call them "Developers" or "Programmers."
C#/VB.NET/ASP.NET/SQL7/2000/2005/2008
http://www.vuyiswamaseko.tiyaneProperties.co.za
vuyiswa@its.co.za
www.ITS.co.za
|
|
|
|
|
exactly .... and does not reflect the changes means that in my project the database in the right side in visual studio is not showing the modified tables i mean the new tows which i have added to the table...
|
|
|
|
|
Delete the Connection and recreate it , it should appear. But before you do that try to refresh it first from the Server explorer. i dont use Wizards for my database work.
Vuyiswa Maseko,
Few companies that installed computers to reduce the employment of clerks have realized their expectations.... They now need more and more expensive clerks even though they call them "Developers" or "Programmers."
C#/VB.NET/ASP.NET/SQL7/2000/2005/2008
http://www.vuyiswamaseko.tiyaneProperties.co.za
vuyiswa@its.co.za
www.ITS.co.za
|
|
|
|
|
if i recreate a new connection then i am loosing the queries i built in the dataset designer.... is it possible to make it without looosing the queries...?
|
|
|
|
|
If the Refresh in the server explorer does not work , unfortunately you will have to loose them.
Vuyiswa Maseko,
Few companies that installed computers to reduce the employment of clerks have realized their expectations.... They now need more and more expensive clerks even though they call them "Developers" or "Programmers."
C#/VB.NET/ASP.NET/SQL7/2000/2005/2008
http://www.vuyiswamaseko.tiyaneProperties.co.za
vuyiswa@its.co.za
www.ITS.co.za
|
|
|
|
|
Hi,
I want to disable all the keyboard and mouse event, but at the same time i want to show a popup where user can enter only numbers and press enter if the value is matched then all the event should be released . I tried using blockinput event but it's blocking all the events and i m not able to unblock it..
Any help would be aprciated...
thanks in advance
Prem..
modified on Thursday, April 16, 2009 10:24 AM
|
|
|
|
|
Hi,
I have implemented a device driver in state machine model using C# i.e based on the previous states output new state has to be initiated in one module.in every state i am sending info to Reader connected through serial port.Timer will be running parelally and checking for the data received event of Serial port and once data received state will be moved to nextstate.Its working fine but very inconsistent.Say executing some states and stopping there and waiting for the reply from Serial port.I cant understand whether its Timer problem or serial port problem.Can any one please reply .I will post the code used here which i used for stop module.
private void tmrCOMM_Tick(object sender, EventArgs e)
{
try
{
tmrCOMM.Enabled = false;
#region " Timeout "
if (blnCheckTimeOut)
{
intTimeout++;
if (intTimeout == 200) // 50 * 100 ms
{
AddLog("Timeout, no response from reader!");
intTimeout = 0;
intNextState = STATE_NOTHING;
intState = STATE_NOTHING;
tmrCOMM.Enabled = true;
blnCheckTimeOut = false;
Array.Resize(ref gblbMsgIn, 0);
return;
}
}
#endregion
switch (intState)
{
case STATE_STOP:
lstLOG.Items.Clear();
AddLog("STOP VarioSens...");
RetryCntr = 0;
intState = STATE_STOP_SND_GET_INV;
break;
case STATE_STOP_SND_GET_INV:
{
RetryCntr++;
StopVarioSens sv = (StopVarioSens)pMain.Controls[0];
sv.lblUID.Text = "";
Array.Resize(ref gblbMsgOut, CommandSet.bInventory().Length);
gblbMsgOut = CommandSet.bInventory();
blnRecordReceived = false;
blnCheckTimeOut = true;
intTimeout = 0;
intState = STATE_STOP_RCV_GET_INV;
AddLog(">> Inventory: " + Helper.ConvertToHexString(gblbMsgOut));
Array.Resize(ref gblbMsgIn, 0);
serialPort1.Write(gblbMsgOut, 0, gblbMsgOut.Length);
}
break;
case STATE_STOP_RCV_GET_INV:
if (blnRecordReceived)
{
blnRecordReceived = false;
if (gblbRecord[4] == 0)
{
RetryCntr = 0;
AddLog("<< Reply: " + Helper.ConvertToHexString(gblbRecord));
StopVarioSens sv = (StopVarioSens)pMain.Controls[0];
sv.lblUID.Text = "";
Array.Resize(ref gblbUID, 0);
for (int i = 0; i < 8; i++)
{
sv.lblUID.Text += string.Format("{0:x2}", gblbRecord[13-i]).ToUpper();
if (i < (gblbRecord.Length - 1))
sv.lblUID.Text += " ";
Array.Resize(ref gblbUID, gblbUID.Length+1);
gblbUID[gblbUID.Length - 1] = gblbRecord[6+i];
}
intState = STATE_STOP_SND_SET_PASSIVE;
}
else
{
AddLog("<< Reply: " + sGetVarioSensErrorDescription(gblbRecord[4]));
if (RetryCntr < 3)
{
intState = STATE_STOP_SND_GET_INV;
}
else
{
intState = STATE_NOTHING;
}
}
}
break;
}
}
Ayyappa Konakalla
|
|
|
|
|
Hello ,
I'm facing a problem ,
when i open 2 dialogs in my project my application icon disappear instead i get the ugly .net default icon showing there are 2 windows open , when i click on it , i can see the two different windows with the icons ,
my question is how can i prevent my application icon to disappear and keep it visible no matter how many open dialogs I'm viewing.
thanks in advance!
Net
|
|
|
|
|
With addition to above question
I am facing the same problem
When we click ALTER + TAB to see/select the applications running currently
it shows the same ugly icon in the list
if anybody have solution
please share with us!!!
Thanks in advance
Deep
Happy Coding
|
|
|
|
|
Rightclick on the solution in the 'Solution Explorer', and choose "Properties". Go to the tab labeled "Application", and verify that you have assigned an icon to the application (not just the mainform, as the mainform.icon != app.icon)
I are troll
|
|
|
|
|
yes i got the icon set in the application tab
and in the main form it still happens.
Net
|
|
|
|
|
there is an Icon property of form, you have to change it for each form.
TVMU^P[[IGIOQHG^JSH`A#@`RFJ\c^JPL>;"[,*/|+&WLEZGc`AFXc!L
%^]*IRXD#@GKCQ`R\^SF_WcHbORY87֦ʻ6ϣN8ȤBcRAV\Z^&SU~%CSWQ@#2
W_AD`EPABIKRDFVS)EVLQK)JKQUFK[M`UKs*$GwU#QDXBER@CBN%
R0~53%eYrd8mt^7Z6]iTF+(EWfJ9zaK-iTV.C\y<pjxsg-b$f4ia>
-----------------------------------------------
128 bit encrypted signature, crack if you can
|
|
|
|
|
Thanks for reply Xmen!!!
This also does not work
i have done what yous said for each form in my application with addition to ShowInTaskBar property to true
however icons disappears from task bar when two or more forms are opened in the application specifically OS creates the stack(Re-groups) if other more applications are opened, and this time the icon of the stack representing my application change to icon which we can see when we choose new icon file in the Visual studio
|
|
|
|
|
does your icon contains 16x16 format ?
TVMU^P[[IGIOQHG^JSH`A#@`RFJ\c^JPL>;"[,*/|+&WLEZGc`AFXc!L
%^]*IRXD#@GKCQ`R\^SF_WcHbORY87֦ʻ6ϣN8ȤBcRAV\Z^&SU~%CSWQ@#2
W_AD`EPABIKRDFVS)EVLQK)JKQUFK[M`UKs*$GwU#QDXBER@CBN%
R0~53%eYrd8mt^7Z6]iTF+(EWfJ9zaK-iTV.C\y<pjxsg-b$f4ia>
-----------------------------------------------
128 bit encrypted signature, crack if you can
|
|
|
|
|
absolutely!!!!!!!
we can not provide 32x32 icon for form if we do so, we wont see it at the start of the title bar of the Form
|
|
|
|
|
SaveTigers wrote: we wont see it at the start of the title bar of the Form
that means its something wrong with your windows
TVMU^P[[IGIOQHG^JSH`A#@`RFJ\c^JPL>;"[,*/|+&WLEZGc`AFXc!L
%^]*IRXD#@GKCQ`R\^SF_WcHbORY87֦ʻ6ϣN8ȤBcRAV\Z^&SU~%CSWQ@#2
W_AD`EPABIKRDFVS)EVLQK)JKQUFK[M`UKs*$GwU#QDXBER@CBN%
R0~53%eYrd8mt^7Z6]iTF+(EWfJ9zaK-iTV.C\y<pjxsg-b$f4ia>
-----------------------------------------------
128 bit encrypted signature, crack if you can
|
|
|
|