|
I don't know if ou remember this or not but I had rough time with you and Judah in my initial posts. I really thank you for being gentle after that. I would have ripped off the guy forever if I was you.
"The worst code you'll come across is code you wrote last year.", wizardzz[ ^]
|
|
|
|
|
I tend not to remember these things. I've knocked lots of raw posters into being good posters over the years. Apparently I used to help Luc, but I can't remember it (I've posted a heck of a lot of times).
I only remember the really bad ones - the ones who refused to improve.
|
|
|
|
|
Delegats are references type variable in c# which holds references to method at run time,
Two types of delegate Single cast,Multi cast delegates,
Ex:Coffe vending mechaine which holds reference to method at run time about mix of flavour according to user....
|
|
|
|
|
Well, fork me sideways I never knew that. I really need a dripping sarcasm icon.
|
|
|
|
|
d@nish wrote: Luc does not visits Q & A
Nor do I. But I like delegates.
|
|
|
|
|
Hi.
A couple of days ago i had a similar discussion here:
Days ago i had a discussion here:
http://www.codeproject.com/Messages/3923426/Re-Getting-data-from-host-convert-to-string-and-th.aspx[^]
The user called Luc patyn told me to use this code:
using (NetworkStream nStream = new NetworkStream(getSocket(numsock).getSocket(),true)) {<br />
using (FileStream fs = new FileStream("C:\\Users\\Mauri\\Desktop\\" + item.Name, FileMode.Append, FileAccess.Write)) {<br />
using (BinaryWriter writer = new BinaryWriter(fs)) { <br />
for(;;) {<br />
int len=nStream.Read(myReadBuffer, 0, myReadBuffer.Length);<br />
if (len==0) break;<br />
writer.Write(myReadBuffer, 0, len);<br />
}<br />
}<br />
}<br />
}<br />
But my problem is that the socket never returns "0" so it gives a timeout exception:
Unable to write data to the transport connection: An error occurred during connection attempt because the connected part did not properly respond after a period of time, or failed to established connection and connected host has failed to respond.<br />
in this line:
int len = nStream.Read(myReadBuffer, 0, myReadBuffer.Length);
Thanks
|
|
|
|
|
NetworkStream.Read() blocks until data is available, so is pretty much only good for synchronous I/O when you know how many bytes to expect and when. You can use NetworkStream.DataAvailable to check and see if there's data before calling read, but that may not be what you want, in which case you should probably use some asynchronous I/O method.
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Are you sure that error is on the reading line? It looks more like a connection problem.
Read will return 0 if the connection is closed normally. If it is closed unexpectedly you can get exceptions trying to call Read.
|
|
|
|
|
I have a small problem with retrieving a DataTable object from an asynchronous call.
My setup:
I have a Winfom app that has a reference to a library.
In the Library I have a class called Run which does:
public static DataTable GetAsyncDataTable(String Query, CommandType sqlCommandType)
{
Abstract.AbstractSqlCommand mySqlCommand = new Concrete.ConcreteSqlCommand();
mySqlCommand.GetAsyncDataTableBegin(Query, sqlCommandType);
queryDuration = mySqlCommand.queryDuration;
return mySqlCommand.MyTable;
}
In the GetAsyncDataTableBegin method the code is
public override IAsyncResult GetAsyncDataTableBegin(String Query, CommandType sqlCommandType)
{
return GetAsyncDataTableBegin(Query, null, sqlCommandType, null);
}
public override IAsyncResult GetAsyncDataTableBegin(String Query, List<SqlParameter> sqlParameters, CommandType sqlCommandType, String ConnectionString)
{
DateTime nu = DateTime.Now;
SqlCommand command = Get(Query, sqlParameters, sqlCommandType, ConnectionString);
return command.BeginExecuteReader(GetAsyncDataTableEnd, command, CommandBehavior.CloseConnection);
}
In the GetAsyncDataTableEnd Method the code is
public override void GetAsyncDataTableEnd(IAsyncResult myResult)
{
SqlCommand command = null;
SqlDataReader dr = null;
DateTime nu = DateTime.Now;
DataTable myTable = new DataTable();
try
{
command = (SqlCommand)myResult.AsyncState;
dr = command.EndExecuteReader(myResult);
myTable.Load(dr);
MyTable = myTable;
}
catch (Exception err)
{
String poef = err.ToString();
}
finally
{
if (null != dr)
dr.Close();
command.Connection.Close();
DateTime klaar = DateTime.Now;
queryDuration = (klaar - nu).Duration();
string Time = queryDuration.ToString();
}
}
And now my problem: When I call the Run.GetAsyncDataTable (first code block), my data is retrieved asynchronously in another thread but the lines in Run.GetAsyncDataTable keep on running so
queryDuration is 0:00:00.000 and mySqlCommand.MyTable = null;
I do not want to poll to wait while mySqlCommand.MyTable == null. How can I have the DataTable filled in the Run.GetAsyncDataTable method?
In Word you can only store 2 bytes. That is why I use Writer.
|
|
|
|
|
Um ... do you understand what 'asynchronous' means? This is exactly what is supposed to happen; to retrieve the result from an asynchronous call you should provide a callback delegate, which is executed some time later, and in the meantime, your code continues to run. If you want the result to be available 'immediately' on the next line of code, why not use a synchronous query call?
|
|
|
|
|
Hey BobJanova,
I do not want to run an synchronous call to the database because I have sometimes a report running for over more than 1 hour.
Maybe my Run Class should be omitted and my form should use the Abstract/Concrete classes directly
In Word you can only store 2 bytes. That is why I use Writer.
|
|
|
|
|
If you have a report running for an hour you definitely don't want to be waiting for it to return! Yes, using the asynchronous database classes directly, and passing a callback to be called when the report is complete, might be a better way forward.
|
|
|
|
|
But in which class do I define the delegate?
In Word you can only store 2 bytes. That is why I use Writer.
|
|
|
|
|
Wherever you're making the database calls (probably in the main form).
|
|
|
|
|
No in the Concrete classes
In Word you can only store 2 bytes. That is why I use Writer.
|
|
|
|
|
Hey Guys,
I am trying to develop a software which will keep track of time and date that someone worked for a week.
So obviously it should be in some sort of DataGrid format with option to select data and time.
I am curious to know whether there's any sample code on this that i can use.
If not, some help on how to use or sample code about DaatGrid and how that could be changed to have columns for data and time.
Thanks in advance.
|
|
|
|
|
You might find this[^] helpful.
|
|
|
|
|
That one is for a website.
I am thinking about something using C# Win Forms. A desktop application runnning
on Windows.
|
|
|
|
|
I think just about every beginning developer thinks about writing a time management application. There are plenty of examples because most of them think theirs is the best thing ever and want to share their exceptional work. There are also a plethora of examples of using DataGrid, you just have to do a simple search.
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
Mark Nischalke wrote: just about every beginning developer thinks about writing a time management
application
True. But since we're lousy at time management, we never complete one.
Will Rogers never met me.
|
|
|
|
|
How to convert with DateTime.ToString() method given date to yyyy\MM\dd format?
e.g. "2011\06\17"
I would not like to use String.Format(@"{0:D4}\{1:D2}\{2:D2}")
Чесноков
|
|
|
|
|
|
DateTime.ToString(@"yyyy\MM\dd");
|
|
|
|
|
Eraser_stp wrote: DateTime.ToString(@"yyyy\MM\dd");
This code will not work.
If you have this string date = DateTime.Now.ToString(@"yyyy\MM\dd"); again wrong format because you will get this result 2011M6d17
I Love T-SQL
"Don't torture yourself,let the life to do it for you."
If my post helps you kindly save my time by voting my post.
www.cacttus.com
|
|
|
|
|
My bad. Thanks for pointing and correct answer.
|
|
|
|