Quantcast

Maximum PC

It is currently Mon Sep 22, 2014 7:20 am

All times are UTC - 8 hours




Post new topic Reply to topic  [ 2 posts ] 
Author Message
 Post subject: Windows Forms c# questions
PostPosted: Tue Sep 20, 2011 8:51 am 
Little Foot
Little Foot

Joined: Tue Apr 22, 2008 9:24 am
Posts: 126
Does data in DataGridView have to be static? As in, The personal project I'm working on now will scan a network, And display the active IP in one column and CPU name in the other column. But I'm having a hard time figuring one thing out, as in does the data being displayed in the datagrid view have to come from a static source? like, would I have to tell my program to dump the information returned into a database and then have the datagridview display that information? Or can it be done on the fly, as in each time a new set of info is found for a pc, it can be added in memory to the datagridview with a new row?

question number 2.

Progressbars: I have found plenty of tutorials for progress bars such as

Code:
progressBar1.Minimum =0;
progressBar1.Maximum = 100;
progressBar1.Step = 1;
progressBar1.PerformStep();


I see that that block of code would force me click a button 100 times to complete the bar. And that same code can also be put into a timer to make it take 100 seconds to complete the bar. What I don't under stand is how to make that work for say, a file download or a process taking place in the program. For a file download would the code work

Code:
//size of file, I don't know the exact code for this
//but this is the general direction I am heading
ulong fileSize = (file.getfilesize.ToString());
progressBar1.Minimum = 0;
progressBar1.Maximum = fileSize;
progressBar1.step = 1;
progressBar1.PerformStep();


As a very rough example above, would that in theory be how one would have to do it? And that leads me to wonder since that could not be put on a timer, would that have to be put on some sort of background worker for the program?


Top
  Profile  
 
 Post subject: Re: Windows Forms c# questions
PostPosted: Wed Sep 21, 2011 5:53 am 
Bitchin' Fast 3D Z8000
Bitchin' Fast 3D Z8000
User avatar

Joined: Mon Jun 14, 2004 4:04 pm
Posts: 985
Location: Earth
Wow, that's a complicated project!

1. Does a datagridview need a static datasource? Yes and no. DataGridViews require that you pass a data source to it, whether you pass an IEnumerable collection, a Collection of a type or a DataSet, it must be a collection. Your project is a tad more complicated because you'll need to use threads to scan the network, possibly a delegate to trigger a callback/event (i.e., OnAfterNetworkScan -> do something), and a locked resource (i.e. list/collection). Since I'm not a threading guru, please take this with a grain of salt, but once you trigger the callback/event you'll need to update the data source and rebind it to the DataGridView.

Quote:
I see that that block of code would force me click a button 100 times to complete the bar. And that same code can also be put into a timer to make it take 100 seconds to complete the bar. What I don't under stand is how to make that work for say, a file download or a process taking place in the program. For a file download would the code work


Again, it's a tad more complicated. You can't simply put it inside a background thread that steps the counter. Most file downloads are synchronous (i.e., it blocks a thread to do its work, so the app has to wait). C#/.NET has an asynchronous mechanism for almost all Stream/WebRequests. The reason for this is that while most I/O can be done synchronously, sometimes, you can't have the app block a thread for various reasons. When you want the current thread to continue without being blocked, you call an asynchronous method. They typically begin with Begin* and End*. They're a pain to use and a freakin' pain to understand. I don't use them, I hate them and I'm awaiting .NET 4.5 for Microsoft to make it simpler by adding the await keyword to the syntax list. I mean, seriously, when you look into asynchronicity in your app, you're looking at callbacks as tall as the Sears Tower.

If you're really intersted in learning these things, pick up a book on threading, threading patterns, asynchronous programming and events.


Top
  Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC - 8 hours


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group