|
hmm... Yea just like that. Sorry. In C# it's easy to create loading bar there even if i don't have a background in it, But i don't know how to create the (How long will it take to finish copying the file ?) time elapse of it. Hope you can help me.
|
|
|
|
|
Nooo, seriously. Try to answer this problem and figure out the maths under it .
Elementary school problem :
It already took 1 minute to copy 10% of a file.
- How long does it take to copy the whole file ?
- How long will it take to finish copying the file ?
Patrice
“Everything should be made as simple as possible, but no simpler.” Albert Einstein
|
|
|
|
|
oh you never said it. i thought you're giving another example for my situation. if my problem is something like that.
well, if a minute is 10%, then it'll take 10minutes for a whole file.
so 10mins? Hmm... not sure what to do with this? I'm not very good at maths and of all, not a programmer. i just use c# because of its drag n drop environment.
|
|
|
|
|
TimeToSendfile= Timespend * FileSize /FilePartSent
TimeRemaining= TimeToSendFile - Timespend
Patrice
“Everything should be made as simple as possible, but no simpler.” Albert Einstein
|
|
|
|
|
at time=0, the time required to copy a file may as well be a guess ... one doesnt know how long it will take until you've had a couple of 'segments/parts' copied that you can then use to provide finer timing details
(which as a discussion on SO and Raymond Chen indicated about 'Explorer', are guesstimates anyway)
|
|
|
|
|
Garth J Lancaster wrote: at time=0, the time required to copy a file may as well be a guess ... one doesnt know how long it will take until you've had a couple of 'segments/parts' copied that you can then use to provide finer timing details That's why you don't estimate remaining time until a minimum amount of data is sent.
Patrice
“Everything should be made as simple as possible, but no simpler.” Albert Einstein
|
|
|
|
|
ppolymorphe wrote: If it take 1 minute to copy 10% of a file.
- How long does it take to copy the whole file ?
- How long will it take to finish copying the file ?
Obligatory XKCD[^].
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
|
load images in an array in memory, build a timer (there are controls for that) and load the next image to the control when timer has elapsed.
that should get you started. Note that this is by definition multithreaded, which is always fun...
|
|
|
|
|
I am trying to convert an array to a dictionary but my code is throwing a null exception. Below is my code
static void Main(string[] args)
{
Product p1 = new Product();
p1.ProductSkew = 99;
p1.ProductName = "Accord";
p1.Color = "Black";
p1.Price = 35000;
Product p2 = new Product();
p2.ProductSkew = 46;
p2.ProductName = "Corvette";
p2.Color = "Black";
p2.Price = 65000;
Product p3 = new Product();
p3.ProductSkew = 35;
p3.ProductName = "Altima";
p3.Color = "Black";
p3.Price = 32000;
Product[] products = new Product[3];
products[0] = p1;
products[1] = p2;
products[2] = p3;
Dictionary<int, Product> productlist = products.ToDictionary(p => p.ProductSkew, p => p);
foreach (KeyValuePair<int, Product> item in productlist)
{
Product product = new Product();
product = item.Value;
Console.WriteLine(
"\nSkew: {0} \n" + "Name: {1} \n" + "Color: {2} \n" + "Price: {3} \n",
product.ProductSkew, product.ProductName, product.Color, product.Price );
}
Console.ReadLine();
}
}
public class Product
{
public int ProductSkew { get; set; }
public string ProductName { get; set; }
public string Color { get; set; }
public double Price { get; set; }
public void AddProduct()
{
Console.WriteLine("Enter Product Skew.");
this.ProductSkew = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Enter Product Name.");
this.ProductName = Console.ReadLine();
Console.WriteLine("Enter Product Color.");
this.Color = Console.ReadLine();
Console.WriteLine("Enter Product Price.");
this.Price = Convert.ToDouble(Console.ReadLine());
}
}
The syntax seems correct but when I step through the code inside of ToDictionay(), p.ProduckSkew is empty and I don't know why. Any help is greatly appreciated, thanks.
|
|
|
|
|
This is weird. Just copy-pasted your code.
- VS 2013
- .net 4.5
- debug and release
Works as expected.
Best,
John
-- Log Wizard - a Log Viewer that is easy and fun to use!
|
|
|
|
|
Hi, thanks for replying. I think I know what the problem is. In my actual code I set the size of the array to 10 but inserted data into only three of the elements.
So my question is how do I test for null values when converting an array to a dictionary. Thanks for your help.
modified 16-Mar-16 18:29pm.
|
|
|
|
|
The most obvious solution would be to use List<Product> instead of Product[] , and then use Products.Add(...); to populate the collection.
List<Product> products = new List<Product>;
products.Add(p1);
products.Add(p2);
products.Add(p3);
"Fairy tales do not tell children the dragons exist. Children already know that dragons exist. Fairy tales tell children the dragons can be killed."
- G.K. Chesterton
|
|
|
|
|
Just add a where clause in your code like this:
Dictionary<int, Product> productlist = products.Where(b => b != null).ToDictionary(p => p.ProductSkew, p => p);
This will ignore all the null products and convert the rest into dictionary.
|
|
|
|
|
Thank you Mathi, your solution works great. Also I will keep everyone else's suggestions in mind as they are all very valuable, thank you all.
|
|
|
|
|
MadDashCoder wrote: Dictionary<int, Product> productlist Maybe it's because it's just a code sample but here you don't actually make use of the dictionary as such because you don't use its keys - a list would suffice. If it actually has to be a dictionary then I'd suggest you don't name it productlist
If the brain were so simple we could understand it, we would be so simple we couldn't. — Lyall Watson
|
|
|
|
|
MadDashCoder wrote: Product product = new Product();
product = item.Value;
There's no point creating a new Product if you're just going to throw it away on the next line. Just use:
Product product = item.Value;
MadDashCoder wrote: ProductSkew
I think you meant to write ProductSku - a Stock Keeping Unit. "Skew"[^] has a totally different meaning.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
The fixed size array is a nono, this is where you should use some kind of a collection, probablye the List<Product> Matt already suggested.
But if you know beforehand you will need a Dictionary (not sure you do!) maybe you could stuff the fresh products in the dictionary right away?
PS: your Product class deserves to have a constructor that takes the basic values as parameters...
PS2: ... as well as a ToString() to return a formatted representation of itself.
|
|
|
|
|
Message Removed
modified 16-Mar-16 12:40pm.
|
|
|
|
|
I use:
private int _MyProperty
public int MyProperty
{
get { return _MyProperty; }
set { _MyProperty = value; }
}
private int myField;
public void MyMethod(int myField, int myProperty)
{
this.myField = myField;
_MyProperty = myProperty;
} In other words, I only use this when I need to pass the current instance to a method, or need to disambiguate two identical names. And anything starting with "_" is a backing field for a property.
This is (I believe) consistent with the recommended naming practices (which I can't find at the moment, damn it!)
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
OriginalGriff wrote: This is (I believe) consistent with the recommended naming practices Hasn't been that way for a while I'm afraid. MS recommend against using the underscore[^].
This space for rent
|
|
|
|
|
That pretty much contemporary with the Net 1.1 version - if you look at the bottom it's copyright 2005!
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
|
I do not know what a Valley Girl is, but it sounds from the context as though it is a derogatory statement implying a sexist viewpoint. Not appropriate for this site.
However, at the risk of being called a Valley Girl, I use this for all class member etc. I only use unadorned (i.e. not prefixed by scope + '.' ) for method local variables (ones that disappear when you exit the method / property) and global variables (NO! PLEASE DON'T USE GLOBAL VARIABLES! (unless you have inherited some code from the 1960s)). Anything associated with the class is prefixed by this , anything associated with another object is prefixed by the object variable name. This (no pun intended) ensures that everything is explicit. Never give future readers / maintainers the option of misunderstanding. OK, my source code may be a bit bigger with all of the this 's but that is a small price to pay for clarity.
|
|
|
|
|
And if you refactor a field starting with "_" in VS it automatically removes the underscore:
private int _MyProperty;
public int MyProperty
{
get { return _MyProperty; }
set { _MyProperty = value; }
}
If you don't start with an underscore you get Yeuch!
private int MyProperty;
public int MyProperty1
{
get { return MyProperty; }
set { MyProperty = value; }
}
So I guess that MS's right hand isn't talking to it's left hand again...
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|