|
good for you! Nice to hear it works.
|
|
|
|
|
i want to download multiple file and want to show multiple progress bar for each file download progress.i got a code which can download file at a time but i want to start download many files at a time and also like to show progress bar for each file progress
suppose i have one textbox where i will put url and when i click on download button then download will start and a progress bar will be show for showing that file download progress. the same if i put another url in textbox and click on download button then another file download start and another progress bar will be shown to show that file download progress. i want that each file will be downloading in separate thread means my program will be multi threaded.
the code i have for downloading one file at a time.please guide me what to change in code to achieve my goal. thanks
private Queue<string> _downloadUrls = new Queue<string>();
private void downloadFile(IEnumerable<string> urls)
{
foreach (var url in urls)
{
_downloadUrls.Enqueue(url);
}
btnGetDownload.Text = "Downloading...";
btnGetDownload.Enabled = false;
progressBar1.Visible = true;
lblFileName.Visible = true;
DownloadFile();
}
private void DownloadFile()
{
if (_downloadUrls.Any())
{
WebClient client = new WebClient();
client.DownloadProgressChanged += client_DownloadProgressChanged;
client.DownloadFileCompleted += client_DownloadFileCompleted;
var url = _downloadUrls.Dequeue();
string FileName = url.Substring(url.LastIndexOf("/") + 1,
(url.Length - url.LastIndexOf("/") - 1));
client.DownloadFileAsync(new Uri(url), "C:\\Test4\\" + FileName);
lblFileName.Text = url;
return;
}
btnGetDownload.Text = "Download Complete";
}
private void client_DownloadFileCompleted(object sender, AsyncCompletedEventArgs e)
{
if (e.Error != null)
{
throw e.Error;
}
if (e.Cancelled)
{
}
DownloadFile();
}
void client_DownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e)
{
double bytesIn = double.Parse(e.BytesReceived.ToString());
double totalBytes = double.Parse(e.TotalBytesToReceive.ToString());
double percentage = bytesIn / totalBytes * 100;
progressBar1.Value = int.Parse(Math.Truncate(percentage).ToString());
}
tbhattacharjee
|
|
|
|
|
I want to convert a folder full of screenshots into a movie (.avi file) with a certain frame rate, is this possible?
Say the folder has 48 images and the frame rate is 24 frames per second, that would then result with a 2 second long video.
Also, would it be possible to then add sounds to specific points in the video? Say, play "explosion.wav" after 10 seconds?
NOTE: I am not looking for a program that does this, I know they exist. I want to know how to do this with C# code.
|
|
|
|
|
If you are looking for a simple avi video, this[^] might help.
Yuu will need to use their package.
|
|
|
|
|
Tried to run this program to save a screensaver but it doesnt seem to work.
The screensaver is generated from a form and this portion of the code which is for the "save" button creates an object with 0 bytes.
private void button6_Click(object sender, EventArgs e)
{
saveFileDialog1.FileName = "";
saveFileDialog1.Title = "Images";
saveFileDialog1.Filter = "screensaver.scr(*.scr)|*.scr";
saveFileDialog1.ShowDialog();
if (saveFileDialog1.FileName.ToString() != "")
{
System.IO.FileStream fs = (System.IO.FileStream)saveFileDialog1.OpenFile();
pictBox1.ImageLocation = saveFileDialog1.FileName.ToString();
}
savefile.Enabled = true;
}
private void pictBox1_Click(object sender, EventArgs e)
{
}
}
|
|
|
|
|
Where is the save operation?
Use the best guess
|
|
|
|
|
What do you mean by "save a screensaver"??
Your code doesn't make any sense at all. You're letting the user pick a ".SCR" file, which is the extension used by screen saver executable files. Then you're trying to display the contents of that file in a picturebox?? WHAT?? You can't do that as a .SCR file is EXECUTABLE, NOT IMAGE DATA!
And, a little pet peeve of mine ... You're calling .ToString() on the FileName property. FileName returns A STRING, so why are you calling .ToString on a String???
|
|
|
|
|
Dave Kreskowiak wrote: why are you calling .ToString on a String? Pet peeve of mine also; it is amazing how many people do it.
Use the best guess
|
|
|
|
|
I write 2 functions in C# to control the progress in a C++ function, using callback
public partial class HjCalibrateForm : Form
{
public static ProgressForm pro_form;
static void progress_init(int max)
{
pro_form = new ProgressForm();
pro_form.Show();
pro_form.progressBar1.Minimum = 0;
pro_form.progressBar1.Maximum = max;
}
static void setValue( )
{
pro_form.progressBar1.Step = 1;
pro_form.progressBar1.PerformStep();
if (pro_form.progressBar1.Value == pro_form.progressBar1.Maximum)
pro_form.Dispose();
}
}
Then in C++,callback
progress_init(max)
for(int i=0;i<max;i++)
{
……set_value();
}
it runs well when i Debug it, but if i excute it directly. It will fail(just stuck). No error message.
It may be something about the Thread, but i can't get it.
modified 27-Mar-13 23:00pm.
|
|
|
|
|
Define "fail". What does it do and what's expected?? Any error messages?? Is the component that's calling your code single-threaded? Multi-threaded? Is the thread that's calling your code the UI (startup) thread?
|
|
|
|
|
I finally solve it by using CLR . I new a progress form in the clr wapper and then callback it in c++, and all these are compiled to DLL and imported to C#. it runs well. But i don't understant why the C# progress form will fail!
|
|
|
|
|
HI Guys,
Using C#,WPF, MVVM Application. I want to save a string or File path when my application exit and again if i relaunch the application That string has to Show.
Iam using the string for otherpurpose.
Kindly suggest me the way, and any hints are more appreciatable.
Thanks,
TV Krishna Rayalu
|
|
|
|
|
You can use the registry[^], or a .ini or .config file.
Use the best guess
|
|
|
|
|
Thank you. , Storing in Registry is secured ?
|
|
|
|
|
KRISHNARAYALU wrote: Storing in Registry is secured ? I'm not sure what you mean; everything is secured if you back up your system properly.
Use the best guess
|
|
|
|
|
But it is an army application, i need to confirm i have Registry access or not.
Thank you.
krishna
|
|
|
|
|
How can anyone here answer that? You need to talk to the administrator of the systems that you are using.
Use the best guess
|
|
|
|
|
I'm a bit confuse about C# convertion.
What is the difference between three convertion below?
txtValue = (string)a;
txtValue = a.ToString();
txtValue = Convert.ToString(a);
I appreciate any help. 
|
|
|
|
|
Midnight Ahri wrote: txtValue = (string)a;
The typecast operation assumes that the object is of type or subclasses from the target type.
So in the above statement a is assumes needs to have string in it's inheritance hierarchy
You should try the above statement in your C# IDE. If 'a' is of type int or float (or anything non-string), the compiler throws an error since it would be a invalid typecast.
Midnight Ahri wrote: txtValue = a.ToString();
a.ToString call the ToString method that every class inherits from the System.Object[^] class. It does not typecast, it returns a new string representation.
a.ToString would throw a null reference exception if a is null
Midnight Ahri wrote: txtValue = Convert.ToString(a);
Convert.ToString[^] returns String.Empty in case the object passed to it is null, otherwise it first checks for IConvertible and IFormattable ToString implementations in the object and uses them. Finally if those are it functions the same as the object's ToString.
"It was when I found out I could make mistakes that I knew I was on to something."
-Ornette Coleman
"Philosophy is a study that lets us be unhappy more intelligently."
-Anon.
|
|
|
|
|
parths wrote: a.ToString would throw a null reference exception if a is null
No, it doesn't! It will throw a NullReferenceException, since it has no instance to call a method from. Try it!
The universe is composed of electrons, neutrons, protons and......morons. (ThePhantomUpvoter)
|
|
|
|
|
I rechecked what I had typed. Isn't that what I had said?
"It was when I found out I could make mistakes that I knew I was on to something."
-Ornette Coleman
"Philosophy is a study that lets us be unhappy more intelligently."
-Anon.
|
|
|
|
|
Nice try - it almost worked...
The universe is composed of electrons, neutrons, protons and......morons. (ThePhantomUpvoter)
|
|
|
|
|
I really hadn't hadn't got your point the first time around.
Did you mean that saying 'a.ToString would throw an exception' should actually be 'Calling a.ToString would throw an exception'?
Sounds like 2 very different things now that I think about it, although I had actually meant the latter. Thanks for correcting that.
I hope I got it right this time.
"It was when I found out I could make mistakes that I knew I was on to something."
-Ornette Coleman
"Philosophy is a study that lets us be unhappy more intelligently."
-Anon.
|
|
|
|
|
Thank you very much for the answer.
It's really useful. 
|
|
|
|
|
parths wrote: The typecast operation assumes that the object is of type or subclasses from the target type. Actually no, it could be that the (static) type of a has an explicit conversion to string.
|
|
|
|