|
Hello,
VS 2008 SP1
I am using the DownloadDataAysnc. But the ProgressChanged event doesn't show progress until after the data has been downloaded.
Even when I try and download a data which is contained in a big file. The programs remains responsive so I know it is doing something. However, it is when the progress has completed that the progressChanged event fires.
I known this as the progressChanged and the DownloadDataCompleted fire immediately after each other. However, they should be a pause as the file is quite big.
This is the code snippet I am currently using. And the output below. What is strange the e.progresspercentage is 100%. And seems to get called twice.
Many thanks for any advise,
Results:
Progress changed Version userstate: [ Version1 ]
progressBar1.Value [ 100 ]
Progress changed Version userstate: [ Version1 ]
progressBar1.Value [ 100 ]
Completed data: [ 1.0.11 ]
private void UpdateAvailable()
{
WebClient wbCheckUpdates = new WebClient();
wbCheckUpdates.DownloadProgressChanged += new DownloadProgressChangedEventHandler(wbCheckUpdates_DownloadProgressChanged);
wbCheckUpdates.DownloadDataCompleted += new DownloadDataCompletedEventHandler(wbCheckUpdates_DownloadDataCompleted);
DownloadFiles df = new DownloadFiles();
string webServerURL = df.webServerPath;
wbCheckUpdates.DownloadDataAsync(new Uri(Path.Combine(webServerURL, "version.txt")), "Version1");
}
void wbCheckUpdates_DownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e)
{
Console.WriteLine("Progress version changed userstate: [ " + e.UserState + " ]");
progressBar1.Value = e.ProgressPercentage;
Console.WriteLine("progressBar1.Value [ " + this.progressBar1.Value + " ]");
}
void wbCheckUpdates_DownloadDataCompleted(object sender, DownloadDataCompletedEventArgs e)
{
byte[] result = e.Result;
Console.WriteLine("Completed data: [ " + System.Text.ASCIIEncoding.Default.GetString(result) + " ]");
}
|
|
|
|
|
steve_rm wrote: But the ProgressChanged event doesn't show progress until after the data has been downloaded.
Yes, this because of UI thread is different from you background thread.
You have to use Background Worker for resolve is Issue. Where you can so Progressbar continuing along with dowloading.
Here is an sample example of Background worker,
Using the BackgroundWorker Component in .NET 2 applications
Hope this will help you
|
|
|
|
|
Hello,
Thanks for the reply.
According to this msdn.
http://msdn.microsoft.com/en-us/library/system.net.webclient.downloadprogresschanged.aspx
The DownloadDataAysnc does show progress.
Not sure why mine doesn't.
Many thanks for any other suggestions,
|
|
|
|
|
Are you by any chance downloading from a passive FTP-server? Just found this in the documentation;
If the server does not send the size of the downloaded file (such as in the case of a passive FTP connection), ProgressPercentage may always be zero.
What happens if you put a breakpoint in the DownloadProgressChangedEventHandler ? Does the break get hit during download?
I are Troll
|
|
|
|
|
Hello,
I am downloading from a http web server using IIS;
Thanks,
|
|
|
|
|
Can you verify (using a new project, just for testing) whether this adapted code works as expected?
static void UpdateAvailable()
{
WebClient wbCheckUpdates = new WebClient();
wbCheckUpdates.DownloadProgressChanged += new DownloadProgressChangedEventHandler(wbCheckUpdates_DownloadProgressChanged);
wbCheckUpdates.DownloadDataCompleted += new DownloadDataCompletedEventHandler(wbCheckUpdates_DownloadDataCompleted);
string webServerURL =
@"http://download.wikimedia.org/simplewiktionary/20090801/simplewiktionary-20090801-pages-articles.xml.bz2";
wbCheckUpdates.DownloadDataAsync(new Uri(webServerURL));
}
static void wbCheckUpdates_DownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e)
{
Console.WriteLine("Download progres: " + e.ProgressPercentage);
}
static void wbCheckUpdates_DownloadDataCompleted(object sender, DownloadDataCompletedEventArgs e)
{
Console.WriteLine("Completed");
}
static void Main(string[] args)
{
UpdateAvailable();
Console.ReadKey();
}
"The human mind ordinarily operates at only ten 10% of its capacity, the rest is overhead for the operating system"
|
|
|
|
|
Hi,
what Abhijit Jana told you is correct.
Steve1_rm wrote: The DownloadDataAysnc does show progress.
No. What the MSDN page says is "(This event) occurs when an asynchronous download operation successfully transfers some or all of the data." So it tells you some progress has been made, it does however run on some thread (most probably a ThreadPool thread) different from the main thread, and hence it is not allowed to touch any Control.
You may want to read some of my articles:
- http://www.perceler.com/articles1.php?art=asyncpool1[^]
- http://www.perceler.com/articles1.php?art=crossthreads1[^]
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|
|
Hi,
I've got a few comments on the code although it does look essentially correct and I can't see anything that is obviously broken.
1) In the completion handler there is no check for success and without that it is not possible to draw any conclusions about other parts of the operation.
2) In the example given the results string is very short, only 6 characters, and so it is quite possible that the first progress notification is 100%. Log the e.BytesReceived and e.TotalBytesToReceive values to get a bit more info here.
3) Bear in mind that UpdateAvailable will return before the download is complete as DownloadDataAsync is non blocking. This leaves the WebClient object eligible for garbage collection and that could cause problems.
Example code for checking successful completion:
private void DownloadDataCallback (Object sender, DownloadDataCompletedEventArgs e)
{
if (e.Error == null && !e.Cancelled)
{
byte[] data = e.Result;
}
else
{
}
}
I've read the other responses and it has been suggested that you should not update the progress bar directly due to cross thread issues. I disagree as WebClient operates in the same way as BackgroundWorker with event notifications marshaled to the UI thread. This means your code is safe without using Invoke on the controls.
Alan.
|
|
|
|
|
Hello,
I have an application made in visual C# which is largely dependant on communicating with an online MS Access database (hosted on jabry.com). It will have several users who are going to update the information on the database, so having it locally is not an option. I have tested it locally, and it works without any problems. I have no idea how to write the connection string for when it is ONLINE though. I've tried a lot of stuff... but nothing is working.
Any help would be greatly appreciated!
|
|
|
|
|
Define "online"?
If you're talking about user who have to get to the Access database over the Internet, then you've picked the wrong database engine entirely.
|
|
|
|
|
I use sql server but i think it works quite the same
"It will have several users who are going to update the information on the database"
remember to manage threads in your applications if you didn´t do that yet
"I have no idea how to write the connection string"
download microsoft absolute beginners lesson videos (it´s free), there you will find out how to connect to a databade from a asp site
nelsonpaixao@yahoo.com.br
trying to help & get help
|
|
|
|
|
Does the server allow remote connections? I seriously doubt it - databases that are provided by an online webhost are usually not available for connection from your local machine.
Same goes for MySQL en SQL Server. They're usually not open to "the internet", and as such, you cannot use such a database as a shared repository. You can use them in a webapplication, once it is installed there (local!)
I are Troll
|
|
|
|
|
Greetings to everyone ... I have a question Can < I write programs in C # to Micro Controllers, as in the C language >
< Are there any functions to control the language or are of limited use >
|
|
|
|
|
Not that I'm aware of. Depending on the µC you're using, your possible chices will probably be C, some variation of BASIC, or assembly.
Personally, I do all my stuff in assembly with µCs, I've never felt the need to use a higher level language with them.
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn) Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia) Why are you using VB6? Do you hate yourself? (Christian Graus)
|
|
|
|
|
Thank you very much .( DaveyM69) .. But something did not take advantage
1-Can < I write programs in C # to Micro Controllers, as in the C language ???>
2-< Are there any functions to control the language or are of limited use ??? >
|
|
|
|
|
Nasir13 wrote: Can < I write programs in C # to Micro Controllers, as in the C language ???>
Allow me to repeat the same stuff for DaveryM69. NO - you cannot write anything for microcontrollers in C#. C# requires that the .NET Framework be installed on a machine running the code. Since your microcontroller isn't running Windows, this is impossible.
Nasir13 wrote: 2-< Are there any functions to control the language or are of limited use ??? >
The question makes no sense. I have no idea what you're trying to say.
|
|
|
|
|
No, none exist (that I know of).
You could possibly write a wrapper around the microcontroller's opcodes, and write code to generate Hex files from that - effectively a C# to uCxxx compiler, but that is going to be a pretty big task.
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn) Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia) Why are you using VB6? Do you hate yourself? (Christian Graus)
|
|
|
|
|
Totally agree with Davey here. I generally use c/c++ for even embedded processors, let alone micro-controllers.
|
|
|
|
|
Greetings and thank you .. Answer like a fire escape
I am a new user to the language of C #, I used VB to control
May be most programmers in C # to develop the site or building applications
But the question of experience in Imktlk Pic
Can I write programs and transfer the file to Hex in C # ????
|
|
|
|
|
Greetings and thank you .. Answer like a fire escape
I am a new user to the language of C #, I used VB to control
May be most programmers in C # to develop the site or building applications
But the question of experience in Pic
Can I write programs and transfer the file to Hex in C # ????
|
|
|
|
|
There is no compiler for C# to pic or any other microcontroller. It is very unlikely that there would ever be one, nor would I want to use it if there were. C# is heavily heap based; garbage collection is a necessity and would increase in frequency with the reduced memory associated with microcontrollers. If you want a garbage collected memory system in a real-time environment, then you need to think quite carefully about the implications: What happens when you need a variable under interrupt and the garbage collection is required?
I would normally use Assembler, C or C++ but with caution: I never use malloc/free or new/delete in an embedded system because I would expect the unit to run 24 hours a day, 365 days a year. Since malloc/free and new/delete can fragment the heap and cause failure I allocate memory either statically or once only and then re-use. This is not feasible in C#.
No trees were harmed in the sending of this message; however, a significant number of electrons were slightly inconvenienced.
This message is made of fully recyclable Zeros and Ones
|
|
|
|
|
Sorry, I'll have to disagree with most of the above.
I will admit that I am fairly new to C# and .NET!
But, I've been doing embedded systems and coding for over 20 years. I still remember using punched cards, paper tape, teletype terminals, etc.
Right now, as far as I know, there isn't C# compiler that will allow someone to do their embedded OS from scratch.
But, C# isn't magic. In fact, *I* would say that it's light years beyond the horrible job that was done with the C++ spec. IMHO, C++, represents just about everything that could be wrong with a language!
BTW: I've done YACC and other custom compilers/assemblers for micros/minis. Remember, back in the old days, that's often how things were done.
As for the "garbage collection" for C++, that's what gets into a gray area for micros. IMHO, there is no such thing as a "standard" C/C++ compiler. Yea, there's the BS standard. So what? It's vague in areas, and unless you do sizeof for everything, your code will break. Even then, compiler support differs.
So, the point is that for C# (or any other language), there's always "wiggle room" when it comes to how a company will do a compiler for an embedded micro. It would not be "unreasonable" if a compiler company added some other requirements or restrictions in the coding due to the C# intended use of garbage collection. For example, a compiler company may require an explicit call to the GC, and/or additional constructor/destructor coding.
Microsoft made Visual Studio C# output platform and processor independent. So, as long as you have enough memory, in theory, you can run your VS programs on any platform. Again, we get into the "embedded vs Windows" world of things. So, not all of the Windows calls makes sense in an embedded app.
IMHO, it will be hard for any language to compare to C for embedded apps. Sorry, IMHO, C makes far more sense in many way verses assembler. Or, IMHO, any other language. For one thing, C can be coded much faster and is far easier to understand. Also, C can be optimized. People suck at optimizing code. Now, it's very rare that a company has the time or desire to spend time on greatly optimizing code. Heck, I'd say that in 99.9999% of the code that is used by people, from the company's point of view, added features were far more important than speed or stability fixes. So, getting code done quickly often takes much higher priority than speed or compactness.
As for .NET in embedded applications, it's being done. I think a few people on here are involved in .NET on embedded systems.
http://www.embedded.com/news/embeddedindustry/197005919?_requestid=208524[^]
http://blogs.msdn.com/mikehall/archive/2007/02/05/net-microframework-and-windows-ce-what-s-the-difference.aspx[^]
As for me, I'll stick to C for my embedded systems, and I'll use C# for my Windows apps. IMHO, those are the best for each application.
modified on Saturday, August 1, 2009 10:47 PM
|
|
|
|
|
Like you, I grew up with cards and tapes (and am soooo glad those days are over).
I have to disagree with you a bit though:
mustang86 wrote: People suck at optimizing code
Not always. Because the coder knows what hardware result they are trying to achieve (a square wave clock with data as applicable for example) they can often be considerably more efficient than a C compiler which can only optimize the higher level instructions, without regard for the algroithm. A mix of C and assembler is the best way IMHO, with assembler kept for when it is realy needed.
Embedded C++ can be a better choice than straight C, particularly if a project is going to get complex.
mustang86 wrote: So, getting code done quickly often takes much higher priority than speed or compactne
Depends on the company priorities: if you are going to ship hundreds of units, then yes. If you are going to ship hundreds of thousands of units, then hardware cost becomes the priority and the software has to work round it's limitations. Saving peanuts on hardware adds up fast when you ship enough!
No trees were harmed in the sending of this message; however, a significant number of electrons were slightly inconvenienced.
This message is made of fully recyclable Zeros and Ones
|
|
|
|
|
Hi im using VS2008 / SQLServer2005
Im using Linq, ive created my .dbml file - is there a tool in vs2008 that I can use to generate the DAL and/or BLL for basic CRUD operations or do I need to code it myself?
Many thanks,
Chas
|
|
|
|
|
Yes and no. You can use the T4-enigne[^] in VS2k8 to generate the source-code, but then you'd probably have to write the templates yourself.
You can also research MyGeneration [^]or CodeSmith[^].
Good luck
I are Troll
|
|
|
|
|