|
You can calculate a percentage for textual output in addition to a progress bar (I think that's what blackjack meant) by dividing two doubles... of course you should know how to compute a percentage.
Then you can use string functions to round that to a certain number of decimal points, but alas, I don't know the exact syntax.
“Time and space can be a bitch.”
–Gushie, Quantum Leap
{o,o}.oO( Looking for a great RSS reader? Try FeedBeast! )
|)””’) Built with home-grown CodeProject components!
-”-”-
|
|
|
|
|
thanks for your reply, but I fail to see that it could be useful for me
|
|
|
|
|
Well often a textual percentage is displayed on the progress dialog as well, or in its title bar so it can be seen on the task bar.
“Time and space can be a bitch.”
–Gushie, Quantum Leap
{o,o}.oO( Looking for a great RSS reader? Try FeedBeast! )
|)””’) Built with home-grown CodeProject components!
-”-”-
|
|
|
|
|
If you have to do heavy calculation.
A Better idea is to do it 'a part' in another thread.
Use thread safe methods to update your progress bar
|
|
|
|
|
Thank you!!!
|
|
|
|
|
you can use BackGroundWorker For that. becuase if you used progress bar for heavy operation your GUI will not respond becuase it give the priority to operation not GUI so your progress bar will not refresh. use BackGroundWorker Components in C# . that will help you.
cheers,
Abhijit
|
|
|
|
|
ooo thank you... it was very helpful!
|
|
|
|
|
I second that. Threads are always best for long-running background operations, just remember to perform control updates on the control thread, as lisan mentioned.
Using threads will also allow you to have a "Cancel" button that can abort the background operation (if you periodically check for a canceled state in that thread, since actually aborting threads can be dangerous).
“Time and space can be a bitch.”
–Gushie, Quantum Leap
{o,o}.oO( Looking for a great RSS reader? Try FeedBeast! )
|)””’) Built with home-grown CodeProject components!
-”-”-
|
|
|
|
|
hai all:
I am trying to do connect pc with mobile i dont know how to use webservcies to connect them can you help me
|
|
|
|
|
A webservice connects with a server. Do you know anything about web services, or did you just hear about them ? What are you trying to do ?
Christian Graus
No longer a Microsoft MVP, but still happy to answer your questions.
|
|
|
|
|
I have a small problem with a file copy loop the code,
During the loop some of the files encounter a System.UnauthorizedAccessException now i would like it just to skip this file and continue with the loop (copy the rest of the files) but it seems the top layer catch fires and it stops copying.
Code basically looks like this:
Private void dostuff()
{
try
{
CopyDirectory(@"c:\test");
}
catch
{
reporterror();
}
}
Private void CopyDirectory(string target)
{
string[] files = Directory.GetFiles(target);
foreach (string file in files)
{
try
{
File.copy(file, @"d:\")
}
catch
{
}
}
}
Thanks for reading!
|
|
|
|
|
Scalee wrote: File.copy(file, @"d:\")
I suggest you RTFM. If you want to copy a file to d, you need to do someting likke this
Path.Combine(@"d:\", Path.GetFileName(file))
to get the path you want.
Christian Graus
No longer a Microsoft MVP, but still happy to answer your questions.
|
|
|
|
|
I actually have
File.Copy(Element, Dst + Path.GetFileName(Element), true);
So if i get this right if i add catch (UnauthorizedAccessException uae),
It will continue to loop?
|
|
|
|
|
Christian Graus wrote: No longer a Microsoft MVP, but still happy to answer your questions.
No longer? I obviously know nothing about it, but how long does a certification last?
“Time and space can be a bitch.”
–Gushie, Quantum Leap
{o,o}.oO( Looking for a great RSS reader? Try FeedBeast! )
|)””’) Built with home-grown CodeProject components!
-”-”-
|
|
|
|
|
Well, for a start, you know what exception you are getting so you should explicitly handle that one. This your code would become:
foreach (string file in files)
{
try
{
File.Copy(file, targetDirectory);
}
catch (UnauthorizedAccessException uae)
{
Debug.Writeline("Unable to write file {0}", file);
}
}
|
|
|
|
|
Hi
i have a method that fill treeView, i want add node to treeViw by anonymous delegates :
private void GetServerDatabases(TreeView tree, string sqlServerInctance)
{
tree.Nodes.Clear();
Microsoft.SqlServer.Management.Smo.Server server = new Microsoft.SqlServer.Management.Smo.Server(sqlServerInctance);
foreach (Microsoft.SqlServer.Management.Smo.Database db in server.Databases)
{
TreeNode dbNode = new TreeNode(db.Name);
TreeNode tablesNode = new TreeNode("Tables");
TreeNode spsNode = new TreeNode("Stored Procedures");
dbNode.Nodes.Add(tablesNode);
dbNode.Nodes.Add(spsNode);
tree.Invoke(delegate
{
tree.Nodes.Add(dbNode);
});
}
}
but in above code (bold words in last lines), the following error message show me :
cannot convert from 'anonymous method' to 'System.Delegate'
how to solve my problem ?
thanks
modified on Tuesday, August 19, 2008 7:37 AM
|
|
|
|
|
tree.Invoke(new MethodInvoker(delegate
{
tree.Nodes.Add(dbNode);
}));
|
|
|
|
|
Thanks Daniel
my problem was solved, but why cross-thread problem occure (for avoid from cross-thread i have to use anonymous delegates)?
thanks
|
|
|
|
|
hdv212 wrote: but why cross-thread problem occure
That's the rule. Controls can be updated only from the thread which created it.
hdv212 wrote: for avoid from cross-thread i have to use anonymous delegates)?
To avoid cross thread exceptions, there is no need to use anonymous delegates. You use Invoke /BeginInvoke and supply delegate instance as parameter.
Instead of creating separate method, you can use anonymous delegates. There is no other difference.
|
|
|
|
|
Hi all
I want to write a C# program that will run in the background and listen to any Interaction with the printer and write to log files.
Please help by providing a source that can help me learn how to detect if the printer is printer?
I have been Googling but i couldn't get any source. Please help...
Thank you
Mosd
Be what you want to be
|
|
|
|
|
Mosd wrote: have been Googling but i couldn't get any source
Google Result
How To Detect Printer using C#[^]
Mosd wrote: I want to write a C# program that will run in the background and listen to any Interaction with the printer and write to log files.
use C# Brackground worker for that
cheers,
Abhijit
|
|
|
|
|
Hi all,
I have a string as follows.
string str = "the code project";
I want to convert it into rtf format. How can I do it in C#?
Thanks a lot.
I appreciate your help all the time...
CodingLover
|
|
|
|
|
What do you mean rtf format? RTF is a text formatting system, so you can represent this string in many ways in rtf. For instance, you could have the word "the" in red characters and the rest in blue. Have a read of the rtf specifications to see what you need to put in. Here's a link[^] to the Word 2007 version of the rtf format.
|
|
|
|
|
Maybe he just wants to have no formatting, but just the text in rtf format. Like pasting a plain text into Winword and saving it as rtf.
If that's the case, one way is to fill a RichTextBox with your string and the get the value of then 'Rtf' property.
|
|
|
|
|
Yeah, as Blackjack said. It seems a little inefficient to keep a RichTextBox around, but it works and Microsoft will maintain it so you don't have to.
|
|
|
|