|
Member 11504545 wrote: &&
Change that to a single amp. Take a look at some of these results[^]
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
1) DownloadProgress event handler is only called once at the start of the download and never again afterwards.
2) DownloadFileCompleted is called right away, even though the file has not yet completed.
private async Task downloadFileAsync(FileEntity file)
{
try
{
using (WebClient client = new WebClient())
{
string outputFile = string.Format("{0}{1}", downloadPath, Path.GetFileName(file.FileName));
if (File.Exists(outputFile))
{
File.Delete(outputFile);
}
client.DownloadProgressChanged += DownloadProgress(file);
client.DownloadFileCompleted += DownloadFileCompleted(file);
await client.DownloadFileTaskAsync(new Uri(file.FileName), outputFile);
}
}
catch (Exception)
{
throw;
}
}
DownloadProgressChangedEventHandler DownloadProgress(FileEntity file)
{
Action<object, DownloadProgressChangedEventArgs> action = (sender, e) =>
{
double bytesIn = double.Parse(e.BytesReceived.ToString());
double totalBytes = double.Parse(e.TotalBytesToReceive.ToString());
double percentage = bytesIn / totalBytes * 100;
var _filename = file.FileName;
};
return new DownloadProgressChangedEventHandler(action);
}
public AsyncCompletedEventHandler DownloadFileCompleted(FileEntity file)
{
Action<object, AsyncCompletedEventArgs> action = (sender, e) =>
{
var _filename = file.FileName;
};
return new AsyncCompletedEventHandler(action);
}
I created these two event handlers because I'd like to know the name of the file in the events.
What am I doing wrong? Is there a better way to do these two?
Thanks
If it's not broken, fix it until it is
|
|
|
|
|
Again, I'm still very new to Async....
- WebClient.DownloadFileAsync returns void
- WebClient.DownloadFileTaskAsync is awaitable
They're both asynchronous. What's the difference? Why use one over the other?
Thanks
If it's not broken, fix it until it is
|
|
|
|
|
DownloadFileAsync was added in .NET 2.0, and uses the EAP model.
When async / await was added to .NET 4.5, many parts of the BCL were updated with new Task -returning TAP methods, which work better with the new syntax.
The guidance for TAP methods is to add Async to the end of the method name. However, since many EAP methods were already using this suffix, Microsoft decided to use the TaskAsync suffix - hence, DownloadFileTaskAsync .
DownloadFileTaskAsync[^] is the newer method, and is much easier to use with async / await .
Alternatively, you could use the even newer HttpClient[^] class, which was built with async / await in mind from the start.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Thanks! Good answer
If it's not broken, fix it until it is
|
|
|
|
|
Psst try up voting the answer, it is generally appreciated and the correct way to reward a good question.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Hello!
I am absolute new with c# and I wonder what {0} means in that code?
using System;
namespace DataTypeApplication
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Size of int: {0}", sizeof(int));
Console.ReadLine();
}
}
}
Many thanks!!!
|
|
|
|
|
First argument. See Composite Formatting[^] for details.
In this instance, it will always be the string 4 because sizeof(int) is 4 by definition (in C#).
|
|
|
|
|
|
how can i convert hex value present in textbox into rgb and store it into new textbox?
|
|
|
|
|
If you mean your average 6-character hexadecimal RGB value .. it's already RGB.
So exactly what do you want to convert to what?
|
|
|
|
|
That depends on exactly what you want to show!
A "hex number" is technically an RGB code already, but that isn't too useful.
So start by converting it to a Color:
public Color FromHex(string hex)
{
if (!hex.StartsWith("#")) hex = "#" + hex;
return ColorTranslator.FromHtml(hex);
}
Now you can use the colour to set the Text color of the new textbox:
displayTextBox.ForeColor = FromHex(hexTextBox.Text);
Or show what colour it is:
displayTextBox.Text = FromHex(hexTextBox.Text).ToString();
Or it's RGB values:
Color c = FromHex(hexTextBox.Text);
displayTextBox.Text = string.Format("{0}:{1}:{2}", c.R, c.G, c.B);
[edit]"ForColor" changed to "ForeColor" - Thanks Richard![/edit]
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
modified 8-Apr-15 14:17pm.
|
|
|
|
|
OriginalGriff wrote: ForColor
I didn't realise you'd been affected by the great Welsh "E" drought. Here, have a few of mine to use:
Eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee!
I think you meant "ForeColor".
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
No, I'm trying to convert my monitor to CMYK and missed out the "U"...
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
how can we share files in .net on a single pc while files are stored in same database?
|
|
|
|
|
Share with who? And what files woul you store in a database?
|
|
|
|
|
Elaborate more, this insufficient information to get exact problem.
modified 20-Sep-20 21:01pm.
|
|
|
|
|
i have been workinng with how to make androide xml analser. i cant come up with the answer.
|
|
|
|
|
what do you want to specifically?
Life's like a nose, you've got to get out of it whats in it!
|
|
|
|
|
You need to make a specification of what you want this analyser to do. Once you have the specification you will then be able to break it down into smaller jobs and it wont seem so hard.
Every day, thousands of innocent plants are killed by vegetarians.
Help end the violence EAT BACON
|
|
|
|
|
Hey,
first, if i writing on bad category, im sorry, i didnt found the help category..
Okey, to my problem. I have a RGB STRIP connected to Arduino, when im communicating via Serial. All works great! So next i wanted to make some audio visualisation.. So i found some samples etc.. and then i created the Audio Visualisation via C# using BASS.NET, when R has been BASSes, G medium frequency and B high frequency. But isnt looking good, so i started thinking, what 3 variables in song has can use, but this is bad idea.. I got idea to change to random color when its get "beat" or BASS hit some value. I tryied 4 hours of doing it, searching, programming... But i cant do it... Im only 15 and non english so im limited in searching etc...
So, my question is how to detecting the beat or just anything event for Audio Visualisation. Best output form WASAPI. Im out of ideas and anything.. Only what i can do is get FFT and Audio Spectrum from WASAPI by BASS.NET, but thats all. My audio skills is so low for this. Anything is welcome!
Thanks.
|
|
|
|
|
You might want to search for the term BPM (Beats Per Minute). (if not done so already)
Hope this helps.
|
|
|
|
|
Yes, i found something with BPM, but i cant integrate that for the BASS.NET, and i didnt found any example for using it in WASAPI. Is possible to provide some example to BPMCounter for WASAPI in bass.net?
Thanks
|
|
|
|
|
I have a form with a few textboxes and checkboxes. I want to store in database values from them. But, I also have a button that selects an image from computer and show link of the image in a textbox. Well, I want to insert data but without inserting an image and here comes my problem, I receive: Empty path name is not legal . Can anybody help me? Thanks
Code is here:
try
{
byte[] imageBt = null;
FileStream fstream = new FileStream(this.textBox5.Text, FileMode.Open, FileAccess.Read);
BinaryReader br = new BinaryReader(fstream);
imageBt = br.ReadBytes((int)fstream.Length);
SQLiteCommand com = new SQLiteCommand("insert into questions(question,answer1,answer2,answer3,option1,option2,option3,category,qcategory,indexrow,indexyes,indexno,cherowstart,cheyes,cheno,currentrow,image) values('" + textBox1.Text + "','" + textBox2.Text + "','" + textBox3.Text + "','" + textBox4.Text + "','" + result1 + "','" + result2 + "','" + result3 + "','" + comboBox1.SelectedItem + "','" + comboBox2.SelectedItem + "',0,0,0,0,0,0,0,@IMG)", Conexiune.getConnection());
com.Parameters.Add(new SQLiteParameter("@IMG", imageBt));
com.ExecuteNonQuery();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
Code for image selection:
try
{
OpenFileDialog dlg = new OpenFileDialog();
dlg.Filter = "JPG Files(.jpg)|.jpg|PNG Files(.png)|.png|All Files(.)|.";
if (dlg.ShowDialog() == DialogResult.OK)
{
string picLoc = dlg.FileName.ToString();
textBox5.Text = picLoc;
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
|
|
|
|
|
I don;t see you loading anything in the picturebox, but I do see a SQLite database being opened. Is the connection opened correctly?
You would start by showing not "ex.Message", but "ex.ToString()", as that will also include a hint as to "which" code went wrong.
You should also read up on SQL-injection, as that is one of the worst ways to build a SQL-statement. It is hard to read, hard to maintain, and it is a security issue.
When done, check out what a using-clause is. That way your connection and command would be disposed when done.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|