|
Cheers for the reply. As I said, I need to display the current transfer progress for each file aswell as the total progress for all files so I need to write byte by byte (which it is doing) and then update the UI's progress bar with the current progress after each byte has been written. I'm not sure which loops you see as unnecessary btw as all 3 of them have a purpose. As for the workers' ProgressChanged event, it only has one value for percent complete and I need two.
modified on Wednesday, July 2, 2008 8:23 AM
|
|
|
|
|
First off, ignore the ReadAllBytes suggestion, if your files are 40MB and you do have a few of them then its going to suck up alot of memory.
If you copy the file like this, you will be able to keep track of where you are:
const int BUFFERSIZE = 32768;
int bytesRead = 0;
long totalBytesRead = 0;
long fileSize = 0;
FileStream input = new FileStream("myfile", FileMode.Open);
FileStream output = new FileStream("mydestination", FileMode.Create);
byte[] buffer = new byte[BUFFERSIZE];
fileSize = input.Length;
.
while(totalBytesRead < fileSize)
{
bytesRead = input.Read(buffer, 0, BUFFERSIZE);
output.Write(buffer, 0, bytesRead);
totalBytesRead += bytesRead;
}
Don't copy the file one byte at a time either, it will just go really slow. You can see your progress by checking totalBytesRead against fileSize .
Infact, you could set up an event and fire it in the while loop. Your main thread could then use this to update your progress bar etc.
My current favourite word is: I'm starting to run out of fav. words!
-SK Genius
Game Programming articles start - here[ ^]-
|
|
|
|
|
Legend! Marriage proposal is in the post ![Smile | :)](https://www.codeproject.com/script/Forums/Images/smiley_smile.gif)
|
|
|
|
|
I'm not sure I'd would do this the same way, totalBytesRead would have to be class variable and volatile to display it on the UI. Else the worker has a copy of the original data and can't change it.
Why not use a delegate you could invoke to update the UI from the worker?
-Spacix
All your skynet questions[ ^] belong to solved
I dislike the black-and-white voting system on questions/answers.
|
|
|
|
|
I did say you could set up an event and trigger that during the loop, you would pass a copy of totalBytesRead and fileSize through that to the main thread.
My current favourite word is: I'm starting to run out of fav. words!
-SK Genius
Game Programming articles start - here[ ^]-
|
|
|
|
|
This is an example of what I've done, just in case anybody else needs something similar in the future. Cheers for your help guys.
FileCopyTest.zip[^]
|
|
|
|
|
Hi All,
I am encountered a problem when I build my project , all Time "Compilation Error" appear !!!
what is the problem?
how can i solve that's problem ?
Ala Qunaibi
modified on Wednesday, July 2, 2008 7:28 AM
|
|
|
|
|
ALAQUNAIBI wrote: what is the problem?
Your code is broken.
ALAQUNAIBI wrote: how can i solve that's problem ?
Fix the code.
|
|
|
|
|
Fantastic, sometimes the solution can be so simple! ![Smile | :)](https://www.codeproject.com/script/Forums/Images/smiley_smile.gif)
modified 12-Sep-18 21:01pm.
|
|
|
|
|
leppie wrote: ALAQUNAIBI wrote:
what is the problem?
Your code is broken.
ALAQUNAIBI wrote:
how can i solve that's problem ?
Fix the code.
That's real experience speaking there. Damn, you and your years of coping with subtle problems like this.
|
|
|
|
|
1st read the error message, it will contain clues as to what you have done wrong.
2nd, Google for the error message, other people may have asked about it before so you might find clues.
3rd, when and only when you have done both of the above, if you are still stuck, post the full error message displayed, and the line of code that it says causes the error and we'll try to help.
Simon
|
|
|
|
|
I have a treeview control whose particular node needs to be dynamically selected during page load. Kindly let me know the way to do this.
|
|
|
|
|
TreeView treeView = new TreeView();
treeView.Nodes.Add("Monday");
treeView.Nodes.Add("Tuesday");
treeView.SelectedNode = treeView.Nodes[1];
Something like that anyway This would select the "Tuesday" node.
|
|
|
|
|
No this does not work. Thanks anyways.
The scenario is something like this.
1. On one page I have a tree view.
2. I select a node and add the node vale in a session variable.
3. On another page I have the treeview.
4. Here I fetch the session variable i.e. the selected node value.
Now I have to use this variable to automatically select the same node.
|
|
|
|
|
For some business reasons, i need my win form app run with fullscreen and not allow user to click any hot keys (such as windows button, alt+tab ,etc.) to go back to desktop or close the program.
is it possible to do this?
thank
^^
|
|
|
|
|
i read somewhere that we have three ways of showing forms/dialogs (i did not remember exact text)
1- normal form.Show()
2- modal form.ShowDialog()
3-system modal ?
i don't know how to have system modal but it said that it will work for your purpose
I Wish the Life Had CTRL-Z
Wizard's First Rule : People are fool,they believe what they want to believe or what they afraid to believe
www.subaitech.blogspot.com
|
|
|
|
|
No, it's not.
The user has, and always should have final control of their PC. There is no way to intercept the Ctrl+alt+del button press. Only the WinLogon process can receive notification of this key combo.
What is your reason for wanting to do this?
Simon
|
|
|
|
|
bug_aonz wrote: For some business reasons...
Yeah, right. Am I the only one who smells malware?
|
|
|
|
|
not neccecaraly...
i wanted to do the same thing last year trying to port the examination system we used at my collage to C#... if your writing an exam you dont want students googling the questions... so thats a perfectly legit reason to want this...
Harvey Saayman - South Africa
Junior Developer
.Net, C#, SQL
you.suck = (you.passion != Programming)
|
|
|
|
|
Don't have browsers on the computers.
Don't attach the computers to the Internet.
Detect the attempt and fail the student.
Mightn't they still be able to use a Web-enabled phone?
|
|
|
|
|
The propose is to prevent shop attendant not to use any thing except only my program which is developed for product ordering.
|
|
|
|
|
If that's the case, try to find information on how an information kiosk works (tourist info, trains, buses, those types). Most run Windows XP, but there is only one usable application.
|
|
|
|
|
They generally don't have QWERTY keyboards attached to them. You can probably intercept most key combinations using the UserActivityHook class here:
http://www.codeproject.com/KB/cs/globalhook.aspx[^]
The user will always be able to Ctrl -> Alt -> Delete and Ctrl -> Shift -> Esc it though. Why not just remove those buttons from their keyboard? Save a lot of hassle ![Smile | :)](https://codeproject.global.ssl.fastly.net/script/Forums/Images/smiley_smile.gif)
|
|
|
|
|
Hello there.
When i run my MDIChild style window the second time, it occured an error:
OutOfMemoryExcpetion-Create handle failed.I don't known why, because some child windows can't occured this error.
Code like below:
dlg.MdiParent = this;
dlg.Show();
The first time i run this code it work correctly, but when i run it again that error occured.
Any help?
Thanks in advance!
If we dream, every thing is possible!
|
|
|
|
|
dealon,
Whats your program doing?, and what happens in the form you load?
Regards,
Gareth.
(FKA gareth111)
|
|
|
|