|
Hello everyone,
I can not find answer from MSDN. My question is, when Console.ReadKey is called on a thread,
1. the thread will be still in running status (like we call Sleep), which will consume CPU time?
2. or the thread will be in wait status like we call WaitOne, and keyboard press will signal the event?
thanks in advance,
George
|
|
|
|
|
ReadKey will block till it gets a key press. IT should not use any CPU while in this state. I am not sure what you mean by the rest of the question.
|
|
|
|
|
Thanks leppie,
Question answered. Cool!!
regards,
George
|
|
|
|
|
Hi everybody,
in my project i receive via sockets an array of bytes.
I send the data from a C++ application to my C# instance.
The Byte-Array is decoded via ASCIIEncoding.ASCII.GetString()
For all standard-chars it work fine, but special characters like ä,ö,ü
aren't translated correctly.
I did a test with a loop, which creates me a byte-array from 0 to 500
then i decode it with ASCIIEncoding.ASCII.GetString() into a string.
I can't find the ä,ü,ö characters into the created string.
if i write string s = "äöü"; the characters are also recognized and are
working correctly.
How i can translate my byte-array that i get the correct characters?
Big thanks for any help
|
|
|
|
|
Use Encoding.Default or a UTF8 or Unicode one.
|
|
|
|
|
I've tested different encodings, UTF8, Unicode, ... nothing worked for me
then a simple Encoding.Default, like you told me works perfect
Big thanks to you !
|
|
|
|
|
hii,
i have been asked to move our company solution over Source safe, im searching for source safe titurials i will be more than happy if some one till me how to use source safe
Thanks 4 all..
|
|
|
|
|
mrcooll wrote: i have been asked to move our company solution over Source safe
Run away!!!
Seriously, what source control are you on now? Why do you think that VSS is a better solution?
You might want to look at other solutions such as SourceGear's Vault. Eric Sink has some excellent tutorials on using that.
|
|
|
|
|
hi,
m asking about vss couse i have never heared about athour solution,
i have noticed that vss is bad!!!
where i can find this sourceGear's valut .
|
|
|
|
|
mrcooll wrote: where i can find this sourceGear's valut .
You could have Googled it[^] by now.
|
|
|
|
|
hey
i use subversion(the server) and tortoise SVN(the client).
i have no complaints so have a look at that
good luck!
Harvey Saayman - South Africa
Junior Developer
.Net, C#, SQL
think BIG and kick ASS
you.suck = (you.passion != Programming)
|
|
|
|
|
Hello,
I think this is the first time i post a question on the codeproject, so hope it goes well
So, the question is:
How can i lock a file while it is being written so that other processes cannot move/delete or access it.
I have a file that is being written into by an application on a remote machine and a windows service on the local machine that connects to the remote machine and downloads that file.
The problem is that i want to download the file only after the write process has stopped completely.
How can this be done?
And a related question: How can this be done if i try to download the file from a ftp server.
Both remote and local machine are under XP and the applications are written in c#.
Thank you
|
|
|
|
|
Pass FileShare.None to constructor of FileStream class.
Giorgi Dalakishvili
#region signature
my articles
#endregion
|
|
|
|
|
hi , i need to generate an array of random numbers which are all different. How can i do so? I am using a while loop and .contains of an arraylist. Can someone tell me please?
Thanks
|
|
|
|
|
Use the random class
int num = random.Next();
Bob
Ashfield Consultants Ltd
|
|
|
|
|
create empty list of ints called used.
N = number of random integers you want.
i = 1
R: generate random number r
if r is in used
goto R
add r to used
i++
if r < N
goto R
loop ends here
I'll leave it to you to translate that to code. Make sure you don't use goto !
Cheers,
Vikram.
The hands that help are holier than the lips that pray.
|
|
|
|
|
i'd create an arraylist with all the numbers in order and an empty arraylist.
then get a random number minimum 0 and less than the length of the arraylist. move that item from the first list to the second and repeat until the first arraylist is empty.
As a separate thought, what would happen if you implemented Icomparable and randomly returned -1 or +1 and then used it for a sort?
|
|
|
|
|
hell it even works
al.Sort(r);
class Randomizer : IComparer
{
#region IComparer Members
Random r = new Random();
public int Compare(object x, object y)
{
if (x == r) return 0;
return r.Next(2) - 1;
}
#endregion
}
}
I'll leave it to anyone who wants to try it to build an arraylist of stuff and work out the type of r
|
|
|
|
|
Russell Jones wrote: implemented Icomparable and randomly returned -1 or +1 and then used it for a sort?
Interesting idea. but the distribution of your list would not be random.
It would depend on the sorting algorithm used.
Simon
|
|
|
|
|
that's true.
I seem to remember about one of the early poker sites that screwed up with their random shuffling routines allowing players to effectively read other people's cards. It's alot harder to get properly random output than it first appears.
Russell
|
|
|
|
|
Russell Jones wrote: i'd create an arraylist with all the numbers in order and an empty arraylist.
then get a random number minimum 0 and less than the length of the arraylist. move that item from the first list to the second and repeat until the first arraylist is empty.
We had this discussion before, Mr. Jones[^]
Cheers,
Vikram.
The hands that help are holier than the lips that pray.
|
|
|
|
|
ha brilliant,
I can't believe that with the number of posts you must read in a day you can remember a post from March, let alone take time to find it.
I notice that Christian's suggestion of a custom sort must have stuck in my brain.
Point taken but my answer still stands
|
|
|
|
|
This will pick ten unique numbers in the range 1 to 100, sorted from lowest to highest:
int range = 100, cnt = 10;
int[] num = new int[cnt];
Random rnd = new Random();
for (int current = 1; cnt > 0; current++) if (rnd.Next(range--) < cnt) num[num.Length - (cnt--)] = current;
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
If you use .NET 3.5 you can also use a HashSet :
do { set.Add(rand.Next(min, max)); } while (set.Count < 10);
modified 12-Sep-18 21:01pm.
|
|
|
|
|
Is there a way to create a dll with classes that incorporate Windows Forms?
I was thinking of collecting some of the functionality for Windows Forms I re-use but Visual Studio won't let me use the System.Windows.Forms namespace in a DLL.
Why is that anyway?
I mean surely the namespace itself is inside a dll that visual studio uses?
Is there any way to create a DLL with the System.Windows.Forms namespace?
Thanks in advance
|
|
|
|