|
Be sure to run the code from the prior post in a separate thread, or Windows will assume your program is "hung" for long directory searches (such as the entire C drive), and when you do a ctl-alt-del your program will appear in the list as not responding (if not in a separate thread).
Jeff
|
|
|
|
|
Thats why i added in to use Application.DoEvents() . It gives control to the main window to do what it needs to, process messages, redraw, etc.
Though i agree that you should probably put it in a separate thread, although that will make it a little more difficult to update your textbox, though it shouldn't be too much trouble.
My current favourite word is: PIE!
I have changed my name to my regular internet alias. But don't let the 'Genius' part fool you, you don't know what 'SK' stands for.
-The Undefeated
|
|
|
|
|
hi,
Directory.GetFiles(string path, string searchPattern, SearchOption searchOption)
searches recursively if you ask for it.
Luc Pattyn [Forum Guidelines] [My Articles]
this months tips:
- before you ask a question here, search CodeProject, then Google
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get
- use PRE tags to preserve formatting when showing multi-line code snippets
|
|
|
|
|
The overload of Directory.GetFiles that takes a SearchOption is only available in .Net 3.0 or later, though I agree it's the best option.
Note that this can still take a long time and should still potentially be run on a separate thread.
My posts may include factual data, educated guesses, personal opinion and dry humor. They should not be treated as an official Microsoft statement. Sites of Interest: MSDN Events | US ISV Team Blog
|
|
|
|
|
Jared Bienz [MSFT] wrote: The overload of Directory.GetFiles that takes a SearchOption is only available in .Net 3.0 or later
I have it running on 2.0, it runs fine except it fails searching at the device level
(such as path="C:\") due to an access denied on "C:\System Volume Information\".
Jared Bienz [MSFT] wrote: should still potentially be run on a separate thread
I fully agree; I would suggest to do allmost all multi-file operations on a separate thread,
and in a try-catch construct.
Luc Pattyn [Forum Guidelines] [My Articles]
this months tips:
- before you ask a question here, search CodeProject, then Google
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get
- use PRE tags to preserve formatting when showing multi-line code snippets
|
|
|
|
|
Thanks for your replies,
Is there an easier way for this?
|
|
|
|
|
Hello, I am trying to create a program that reads in 3 numbers and averages them for my Programming 1 class. I am trying to use method call statements in order to do this. I got it all finished but when I built it I got three "Identifier Expected" errors on line 26, and I don't understand what that means. (I'm rather new) Here is what I've got for coding...I'm not sure if there is anything else I need to change about it other than the 3 errors, either.
using System;<br />
using System.Collections.Generic;<br />
using System.Text;<br />
<br />
namespace Program10<br />
{<br />
class Program<br />
{<br />
static void GetNums(out double num1, out double num2, out double num3)<br />
{<br />
Console.Write("Enter first number: ");<br />
num1 = double.Parse(Console.ReadLine());<br />
Console.Write("Enter second number: ");<br />
num2 = double.Parse(Console.ReadLine());<br />
Console.Write("Enter third number: ");<br />
num3 = double.Parse(Console.ReadLine());<br />
}<br />
static void CalcAvg(out double num1, out double num2, out double num3)<br />
{<br />
double avgNum;<br />
avgNum = num1 + num2 + num3;<br />
avgNum = avgNum / 3;<br />
<br />
return (double) avgNum;<br />
}<br />
static double DspAvg(double avgNum, out num1, out num2, out num3)<br />
{<br />
Console.WriteLine("The average of {0:n}, {1:n}, and {2:n} is {3}", num1, num2, num3, avgNum);<br />
}<br />
<br />
static void Main()<br />
{<br />
double firstNum, secNum, thirdNum, avgNum;<br />
DspAvg(firstNum, secNum, thirdNum);<br />
GetNums(out firstNum, out secNum, out thirdNum);<br />
CalcAvg(avgNum);<br />
}<br />
<br />
}
Thanks in advance for your help!
[Ross Murtle]
[Computer Science Major - Iowa Central Community College/Iowa State University]
|
|
|
|
|
and which of these is line 26?
don't tell us you are running Visual Studio with line numbering disabled!
and please use < PRE > tags for code snippets.
Luc Pattyn [Forum Guidelines] [My Articles]
this months tips:
- before you ask a question here, search CodeProject, then Google
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get
- use PRE tags to preserve formatting when showing multi-line code snippets
|
|
|
|
|
static double DspAvg(double avgNum, out num1, out num2, out num3)
is line 26. Sorry for the confusion.
|
|
|
|
|
num1/2/3 are missing their types, something like int
Luc Pattyn [Forum Guidelines] [My Articles]
this months tips:
- before you ask a question here, search CodeProject, then Google
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get
- use PRE tags to preserve formatting when showing multi-line code snippets
|
|
|
|
|
First off, Welcome to Programming C#! It's my favorite language.
There are a handfull of issues, but at least you gave it the good old college try.
Let's get started: You were missing a close curly brace at the end, though that could have simply not made it to your clipboard.
Next, (and this was the 'Identifier Expected' issue) in DspAvg you didn't define the data type for num1 num2 or num3. You must specify that they're double.
After that, in DspAvg you also can't mark those parameters as 'out' because DspAvg never assigns them a value -- it just prints them on the screen. The 'out' keyword signifies that a value will be assigned to the parameter before the method returns.
The same thing happened in CalcAvg. No need to mark them as 'out' since they're not being assigned in the method.
In CalcAvg you explicitly cast avgNum to a double, which isn't necessary since avgNum is defined as a double at the beginning of the method. It'll still compile, but it's unecessary.
Now, here it get's a little interesting. DspAgv is marked to return a double, but no value is returned (and one shouldn't be because you're just displaying the results). However, your CalcAvg method doesn't return a value and of course it really should.
In Main it looks like you were trying to use DspAvg to show the collected values, but DspAvg requires a fourth parameter (the calculated average). You could either remove that parameter or not use DspAvg until you've done the calculation.
In Main, when you call CalcAvg you'll need to store the return value.
You should probably have a Console.ReadLine at the end or the window will close before you see the results (if debugging in Visual Studio).
Here are the changes, hope it works for you. Now please don't expect another free homework assignment, but DO enjoy learning C#.
<br />
using System;<br />
using System.Collections.Generic;<br />
using System.Text;<br />
<br />
namespace Program10<br />
{<br />
class Program<br />
{<br />
static void GetNums(out double num1, out double num2, out double num3)<br />
{<br />
Console.Write("Enter first number: ");<br />
num1 = double.Parse(Console.ReadLine());<br />
Console.Write("Enter second number: ");<br />
num2 = double.Parse(Console.ReadLine());<br />
Console.Write("Enter third number: ");<br />
num3 = double.Parse(Console.ReadLine());<br />
}<br />
<br />
static double CalcAvg(double num1, double num2, double num3)<br />
{<br />
double avgNum;<br />
avgNum = num1 + num2 + num3;<br />
avgNum = avgNum / 3;<br />
<br />
return avgNum;<br />
}<br />
<br />
static void DspAvg(double avgNum, double num1, double num2, double num3)<br />
{<br />
Console.WriteLine("The average of {0:n}, {1:n}, and {2:n} is {3}", num1, num2, num3, avgNum);<br />
}<br />
<br />
static void Main()<br />
{<br />
double firstNum, secNum, thirdNum;<br />
GetNums(out firstNum, out secNum, out thirdNum);<br />
double avgNum = CalcAvg(firstNum, secNum, thirdNum);<br />
DspAvg(avgNum, firstNum, secNum, thirdNum);<br />
Console.WriteLine("Press Enter to end the application.");<br />
Console.ReadLine();<br />
}<br />
<br />
}<br />
}<br />
My posts may include factual data, educated guesses, personal opinion and dry humor. They should not be treated as an official Microsoft statement.
|
|
|
|
|
Thank you SO MUCH for your help. I have learned from my mistakes and the fact that you took time out of your day to help a measly little college freshman like myself is greatly appreciated!
Thanks again!
|
|
|
|
|
No problem at all. The secret to becoming a successful developer is being resourceful and not giving up. Glad I could help.
My posts may include factual data, educated guesses, personal opinion and dry humor. They should not be treated as an official Microsoft statement. Sites of Interest: MSDN Events | US ISV Team Blog
|
|
|
|
|
Jared Bienz [MSFT] wrote: The secret to becoming a successful developer is being resourceful and not giving up
Its not. The secret is caffeine and pizza. Plenty of it.
|
|
|
|
|
Caffeine and Pizza inherit from Resource, don't they?
Luc Pattyn [Forum Guidelines] [My Articles]
this months tips:
- before you ask a question here, search CodeProject, then Google
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get
- use PRE tags to preserve formatting when showing multi-line code snippets
|
|
|
|
|
Luc Pattyn wrote: Caffeine and Pizza inherit from Resource, don't they?
They do. And best of all, they are Disposable - although the Garbage Collection is a bit unpredictable.;)
|
|
|
|
|
Jared Bienz [MSFT] wrote: You should probably have a Console.ReadLine at the end or the window will close before you see the results (if debugging in Visual Studio).
I actually find that:
Console.ReadKey(true);
Is much better, as soon as you press any key (apart from a select few, NumLock, for example) it will close. The 'true' part means that it will not send the input to the buffer, so you won't actualy see the letter or number you pressed on the screen.
My current favourite word is: PIE!
I have changed my name to my regular internet alias. But don't let the 'Genius' part fool you, you don't know what 'SK' stands for.
-The Undefeated
|
|
|
|
|
Ah, much better. Thanks for pointing that out. I'm going to use that from now on in my SequentialWorkflow console demos!
My posts may include factual data, educated guesses, personal opinion and dry humor. They should not be treated as an official Microsoft statement. Sites of Interest: MSDN Events | US ISV Team Blog
|
|
|
|
|
Please help me to find a good and simple Remoting tutorial.
I have 6 mnth exp in c# (So now you know my level of understanding).
Thanks in advance.
v
|
|
|
|
|
Try this[^]. You can find it easily enough by using Google[^]
|
|
|
|
|
Petes article above is a great place to start. You might also want to dive into the .Net Remoting Overview[^] section on MSDN. Specifically there's a good article titled Building a Basic .NET Framework Remoting Application[^]
I'd also like to make sure you're aware of Windows Communication Foundation (WCF). You may have a business reason for using Remoting so I wanted to provide those resources, but if this is a hobby project or you’re starting new product development you really should consider using WCF instead. .Net Remoting will be around for a long time yet, but Microsoft is no longer developing that technology and WCF is the recommended platform for all new communications development.
WCF will still let you do the same things that Remoting will (cross-process communication, fast binary encoding, singletons, serialization, etc.) but it will also let you do so much more. A WCF service can be hosted in-process like a Remoting service can, but it can also be hosted, activated and load balanced on an IIS server. WCF allows the same service instance to be contacted over a binary TCP channel, a SOAP web service channel, a named pipe or even a message queue -- all without changing a single line of code. How a service behaves, how security is applied and how a service communicates can all be described in code or alternatively in an XML configuration file without needing to recompile the application. You can even use WCF to write P2P applications!
If you'd like to check out WCF I recommend you start with http://wcf.netfx3.com[^] or the Windows Communication Foundation[^] area on MSDN.
I hope you find what you're looking for, and happy coding!
Jared
My posts may include factual data, educated guesses, personal opinion and dry humor. They should not be treated as an official Microsoft statement.
|
|
|
|
|
Jared
I'm glad you brought this up, and am kicking myself for not mentioning it myself. Something that you didn't mention, but I think is a big plus, is that WCF also outperforms remoting (in all the cases I've encountered so far). Added to that, the fact that you can change transport mechanisms (within certain limits) without too much trouble, and this is indeed a very powerful way to go forward. There are certain things I would have liked to see present in WCF, but on the whole I really like it (enough that all of my clients are now getting WCF solutions instead of the alternatives).
|
|
|
|
|
Do a search here at CP and there are plenty of good articles.
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
|
|
|
|
|
Hello to all,
I have a dialog box that for now I want to inject the user name and password directly,
I added the values to main and passed to the correct place in the program.
the only problem is the dialog opens and waits for someone to press the "OK" button to proceed.
I want to make the box close by performClick() it self or some other alternative to achieve the same result.
I want this:
if (frmLoginUser.ShowDialog() != DialogResult.OK)
{
return;
}
to exist, but automatically press it's own OK button without any value passed to Dialog.
thank you very much for the help.
|
|
|
|
|
You don't need to click a button to set the dialog result. So you could just add in this.DialogResult = DialogResult.OK and then close the form.
My current favourite word is: PIE!
I have changed my name to my regular internet alias. But don't let the 'Genius' part fool you, you don't know what 'SK' stands for.
-The Undefeated
|
|
|
|
|