|
| Author |
Message |
csharpula csharp
Joined: 11 Aug 2007 Posts: 14
|
Posted: Wed Dec 12, 2007 4:21 am Post subject: Present updating data |
|
|
Hello,
I would like to know how can I present updating (on the fly) data in a
DataGrid type control. The control will get url as an input and need to
present the log changing content in a DataGrid style control.How to do
it in WinForms? Thank you!
*** Sent via Developersdex http://www.developersdex.com ***
Archived from group: microsoft>public>dotnet>languages>csharp |
|
| Back to top |
|
 |
Morten Wennevik [C# MVP]
Joined: 04 Dec 2007 Posts: 14
|
Posted: Wed Dec 12, 2007 4:50 am Post subject: RE: Present updating data |
|
|
Hi,
You can use a BackgroundWorker and manually read the stream, passing a log
entry to the GUI thread using invoke whenever you want.
--
Happy Coding!
Morten Wennevik [C# MVP]
"csharpula csharp" wrote:
>
> Hello,
> I would like to know how can I present updating (on the fly) data in a
> DataGrid type control. The control will get url as an input and need to
> present the log changing content in a DataGrid style control.How to do
> it in WinForms? Thank you!
>
>
> *** Sent via Developersdex http://www.developersdex.com ***
> |
|
| Back to top |
|
 |
csharpula csharp
Joined: 11 Aug 2007 Posts: 14
|
Posted: Wed Dec 12, 2007 5:09 am Post subject: RE: Present updating data |
|
|
Could you please explain how exactly can i do it?
*** Sent via Developersdex http://www.developersdex.com *** |
|
| Back to top |
|
 |
Morten Wennevik [C# MVP]
Joined: 04 Dec 2007 Posts: 14
|
Posted: Thu Dec 13, 2007 5:13 am Post subject: RE: Present updating data |
|
|
If you need to read the url each time you want to update the log status
instead of just once, for a huge log (which my example assumed), rewrite the
download part to reside inside an eternal loop. You need to poll the url
every so often to find out if there are any changes to the log. Remember to
check for CancellationPending inside this loop or the BackgroundWorker won't
stop.
--
Happy Coding!
Morten Wennevik [C# MVP]
"csharpula csharp" wrote:
>
>
> Thanks but I don't understand how can I know that there is an update in
> the log which is located in the url?
>
> *** Sent via Developersdex http://www.developersdex.com ***
> |
|
| Back to top |
|
 |
csharpula csharp
Joined: 11 Aug 2007 Posts: 14
|
Posted: Thu Dec 13, 2007 7:04 am Post subject: RE: Present updating data |
|
|
Hello,
I tried to do this:
while (true)
{
using (Stream s = resp.GetResponseStream())
{
byte[] data = new byte[8192];
int i = 0;
int pos = 0;
while ((i = s.Read(data, 0, data.Length)) > 0)
{
if (worker.CancellationPending)
return;
AddLogEntry("Title",
Encoding.Default.GetString(data), "blabla");
pos += i;
Thread.Sleep(1000);
}
}
}
But I get the following error:
The request was aborted: The connection was closed unexpectedly.
And isn't ther more elegant way than endless loop?
Thank you very much!
*** Sent via Developersdex http://www.developersdex.com *** |
|
| Back to top |
|
 |
Morten Wennevik [C# MVP]
Joined: 04 Dec 2007 Posts: 14
|
Posted: Thu Dec 13, 2007 9:18 am Post subject: RE: Present updating data |
|
|
You need to encapsulate everything including HttpWebRequest.
If the size of the log isn't an issue, you can easily use a WebClient
instead of request/response.
WebClient client = new WebClient();
// Set proxy credentials if needed
client.Proxy.Credentials =
CredentialCache.DefaultNetworkCredentials;
while (true)
{
byte[] data = client.DownloadData();
if (worker.CancellationPending)
return;
AddLogEntry("Title", Encoding.Default.GetString(data));
Thread.Sleep(1000); // For testing purposes
}
You won't have the opportunity to notify the GUI during download, but
usually text is downloaded fairly fast anyway.
However, I'm wondering if maybe you just need a way to download the log once
in the background, in which case just remove the while loop. If you need
regular updates you could also have a timer in the main GUI thread and let
the timer event start the worker.
--
Happy Coding!
Morten Wennevik [C# MVP]
"csharpula csharp" wrote:
> Hello,
> I tried to do this:
>
> while (true)
> {
> using (Stream s = resp.GetResponseStream())
> {
> byte[] data = new byte[8192];
>
> int i = 0;
> int pos = 0;
>
> while ((i = s.Read(data, 0, data.Length)) > 0)
> {
> if (worker.CancellationPending)
> return;
>
> AddLogEntry("Title",
> Encoding.Default.GetString(data), "blabla");
>
> pos += i;
>
> Thread.Sleep(1000);
> }
> }
> }
>
> But I get the following error:
>
> The request was aborted: The connection was closed unexpectedly.
>
> And isn't ther more elegant way than endless loop?
> Thank you very much!
>
>
> *** Sent via Developersdex http://www.developersdex.com ***
> |
|
| Back to top |
|
 |
csharpula csharp
Joined: 11 Aug 2007 Posts: 14
|
Posted: Thu Dec 13, 2007 10:20 am Post subject: RE: Present updating data |
|
|
Hello again,
Well I need some kind of FileSystemWatcher class but which will do the
pooling to the url ,how to do that? The log file I got is being updated
all the time during some process on remote comp and i need that my c#
gui will present the changes all the time. How to do such a Watcher in
the code you posted? Thank u!
*** Sent via Developersdex http://www.developersdex.com *** |
|
| Back to top |
|
 |
Morten Wennevik [C# MVP]
Joined: 04 Dec 2007 Posts: 14
|
Posted: Thu Dec 13, 2007 10:46 am Post subject: RE: Present updating data |
|
|
Ok, correct me if I am wrong.
You have a GUI application on one computer that should display any changes
in a log file on another computer, preferrably as soon as they occur in the
log file?
My code should cover the first part, downloading the log every so often.
As for 'pooling to the url'. I'm not sure what you mean by this. Do you
seek a solution where the remote computer actively updates any client
listening to it? Or maybe have the remote computer 'post' the log file to a
public web site where you can get it to your local computer?
The simplest way would be to have a web service running on the remote
computer with read access to the log file. Whenever you call this web
service (like from a background worker started by a timer) the web service
will then go and get the latest log information.
--
Happy Coding!
Morten Wennevik [C# MVP]
"csharpula csharp" wrote:
> Hello again,
> Well I need some kind of FileSystemWatcher class but which will do the
> pooling to the url ,how to do that? The log file I got is being updated
> all the time during some process on remote comp and i need that my c#
> gui will present the changes all the time. How to do such a Watcher in
> the code you posted? Thank u!
>
>
> *** Sent via Developersdex http://www.developersdex.com ***
> |
|
| Back to top |
|
 |
csharpula csharp
Joined: 11 Aug 2007 Posts: 14
|
Posted: Thu Dec 13, 2007 11:00 am Post subject: RE: Present updating data |
|
|
Hello,
About the gui part - I have a c# gui which communicates via web service
with other computer. There is some process on other computer which
updates the log that I need to present on my computer (with any change).
The question is how will I know that the log is updated and will present
only the "delta" change of the log attached to the previous log data I
presented already?
Thanks a lot!
*** Sent via Developersdex http://www.developersdex.com *** |
|
| Back to top |
|
 |
Morten Wennevik [C# MVP]
Joined: 04 Dec 2007 Posts: 14
|
Posted: Thu Dec 13, 2007 1:01 pm Post subject: RE: Present updating data |
|
|
The web service is not able notify you of any change. The GUI client needs
to regularly call the web service and read the log and compare it with a
local copy.
--
Happy Coding!
Morten Wennevik [C# MVP]
"csharpula csharp" wrote:
> Hello,
> About the gui part - I have a c# gui which communicates via web service
> with other computer. There is some process on other computer which
> updates the log that I need to present on my computer (with any change).
> The question is how will I know that the log is updated and will present
> only the "delta" change of the log attached to the previous log data I
> presented already?
> Thanks a lot!
>
>
>
> *** Sent via Developersdex http://www.developersdex.com ***
> |
|
| Back to top |
|
 |
csharpula csharp
Joined: 11 Aug 2007 Posts: 14
|
Posted: Thu Dec 13, 2007 1:12 pm Post subject: RE: Present updating data |
|
|
Thank u and what is the best way to compare ? Is there a way to read by
lines from a stream (and this will help me to compare) or I will get all
the data in one string?
*** Sent via Developersdex http://www.developersdex.com *** |
|
| Back to top |
|
 |
Ben Voigt [C++ MVP]
Joined: 08 Aug 2007 Posts: 189
|
Posted: Thu Dec 13, 2007 6:23 pm Post subject: Re: Present updating data |
|
|
"Morten Wennevik [C# MVP]" wrote in message @microsoft.com...
> The web service is not able notify you of any change. The GUI client
> needs
> to regularly call the web service and read the log and compare it with a
> local copy.
The web service should be rewritten to return only new entries, this avoid
unnecessarily copying the old section of the log across the network multiple
times.
If the log is append-only, this is as simple as including the file length in
the data from the web service, and passing that to the web service on the
next invocation so it can send the data starting at that position.
>
> --
> Happy Coding!
> Morten Wennevik [C# MVP]
>
>
> "csharpula csharp" wrote:
>
>> Hello,
>> About the gui part - I have a c# gui which communicates via web service
>> with other computer. There is some process on other computer which
>> updates the log that I need to present on my computer (with any change).
>> The question is how will I know that the log is updated and will present
>> only the "delta" change of the log attached to the previous log data I
>> presented already?
>> Thanks a lot!
>>
>>
>>
>> *** Sent via Developersdex http://www.developersdex.com ***
>> |
|
| Back to top |
|
 |
csharpula csharp
Joined: 11 Aug 2007 Posts: 14
|
Posted: Sat Dec 15, 2007 1:10 pm Post subject: Re: Present updating data |
|
|
Is it possible to read oin each iteration from the last readed bytes
till the end? If so ,how should I do it? I want to find a solution which
won't involve making changes in web srvice. Thank you!
*** Sent via Developersdex http://www.developersdex.com ***
|
|
| Back to top |
|
 |
|