|
Anyone here can give me some guides ? ....
|
|
|
|
|
Be patient. This isn't 24x7 support, it's a community forum.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
It helps to know what exception you're getting and what it states. And don't just give me the text from MessageBox.Show (which is not really a debugging tool - try a breakpoint or the Debug or Trace facilities at the very least), the actual exception type is good to know. Besides, in production code you'll give your user 1) a user-unfriendly message, and 2) a malicious user too much information.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
In the try-catch block, this kind of error is showed when i list it out
"Data Error"
Mscorlib (in Mscorlib.dll)
at System.Security.Cryptography.CryptoAPITransform._DecryptData(IntPtr hKey, Byte[] rgb, Int32 ib, Int32 cb, Boolean fDone)
at System.Security.Cryptography.CryptoAPITransform.TransformFinalBlock(Byte[] inputBuffer, Int32 inputOffset, Int32 inputCount)
at System.Security.Cryptography.CryptoStream.Read(Byte[] buffer, Int32 offset, Int32 count)
at WindowsApplication3.Form1.button10_Click(Object sender, EventArgs e)
|
|
|
|
|
You're still not telling me the actual exception Type, only the message.
In any case, try using a buffer that is a power of 2 (2, 4, 8, 16, 32, 64, ...) when decrypting. This is a pretty common requirement when decrypting so that the decryption algorithm has all that it needs to decrypt a block. This usually isn't the case when you don't have a block of the right size, which is almost always a power of 2.
Also, don't new-up a UnicodeEncoding object every time you use it. Use Encoding.Unicode which create a single instance to be used any time you use it, which saves time and memory:
byte[] buffer = Encoding.Unicode.GetBytes(someString);
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Actually, there was no exception being thrown.
If you have seen the code ... the try-catch is something that i insert to see what thing is happening ...
This is because ... the program was hanged in the do loop ...
I don't know how to express ... if you have tried the code, you will know what is happening...
Things made me mad ...
Anyway, u teach me a lot and thanks for your reply ...
i still look forward you can help me to solve this problem ....
|
|
|
|
|
It not exception is being thrown, then what is being caught? Of course an exception is thrown, but you're handling it, at least that's what your code shows.
As I mentioned before, though, decryption typically expects a buffer with a size that is a power of 2 so that it has enough information to decrypt a block. If you don't provide enough information, it doesn't have enough information to decrypt a block of cipher text and would hang waiting for more, or throw an exception. Try resizing your cipher text buffer to be a power of 2 and try again.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Hi all
Can anyone suggest me which way of string replacment is much better ??
1) string str = "Date today is " + Date.Now.ToString() + " !!!!"
Or
2) string str = String.Format("Date today is {0} !!!!",Date.Now.ToString())
Thanxs
Maharishi Bhatia
|
|
|
|
|
Never concatenate strings using + - it's very expensive since two iterations for each string and each concatenation are necessary, making it an (m-1)O(2n) operation where n is the number of character for two strings and m is the number of strings.
Use String.Concat or String.Format like you're doing, but don't use ToString . What do you thing String.Format is for? Lets say you wanted to format the date using the long date format. Just use the following:
string s = string.Format("The date is {0:D}.", DateTime.Now); If you use ToString , you loose that ability (unless you use the overload for DateTime.ToString which takes a string and optionally a different culture's IFormatProvider . I'll be submitting an article on this topic in the next couple days. You might want to keep a look out and read it.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
bloody hell never knew it was expensive to use ToString() !
Well you learn something everyday
|
|
|
|
|
It isn't expensive to use ToString (unless the implementation is crappy), I said it was expensive to concat strings using + . Using ToString in the variable argument list for String.Format (and the like) is not only unnecessary but in many cases dumb since you loose the ability to apply custom formats (unless you pass the format specifiers as args to the ToString overload for the IFormattable implementation).
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Heath Stewart wrote:
Never concatenate strings using + ...Use String.Concat
C# code that 'pluses' strings together gets IL compiled down to .Concat, right? Maybe I'm misunderstanding you.
---------------------------
He who knows that enough is enough will always have enough.
-Lao Tsu
|
|
|
|
|
For the Microsoft C# compiler, yes, and under certain circumstances - which typically warrant String.Format for better control. Depending on the operands you're passing, the compiler doesn't always optimize using String.Concat either.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Well then, if you take into account that it's almost always optimized into String.Concat , then wouldn't you say that using + is actually much quicker than using String.Format , which involves parsing and appending?
From a readibility stand point, the + operator is superior in my opinion. Now, if special formatting is necessary, then the Format method is available -- for formatting purposes.
Regards,
Alvaro
Give a man a fish, he owes you one fish. Teach a man to fish, you give up your monopoly on fisheries.
|
|
|
|
|
It depends on the circumstances, I'd say. Like you said, for special formatting using String.Format is definitely better, though you could accomplish this task with + or String.Concat if you use the overloaded ToString that corresponds to the IFormattable implementation.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
3) string str = "Date today is " + Date.Now + " !!!!";
ToString() is automatically called for you.
Regards,
Alvaro
Give a man a fish, he owes you one fish. Teach a man to fish, you give up your monopoly on fisheries.
|
|
|
|
|
how do i copy files to the clipboard with csharp so that i can right click a dir and past them into it (i really need to be able to past bitmap into a program but its the same principle)
chad
|
|
|
|
|
Read about the Clipboard class in the .NET Framework SDK. You use it in a similar fashion as you do drag and drop. You fill a DataObject with data and add it to the clipboard, only the DragDropEffects is not used.
To add it:
DataObject do = new DataObject(DataFormats.FileDrop,
@"C:\temp\file.txt");
Clipboard.SetDataObject(do, true); To get it:
DataObject do = Clipboard.GetDataObject();
if (do.GetDataPresent(DataFormats.FileDrop))
{
string filename = (string)do.GetData(DataFormats.FileDrop);
File.Copy(filename, destination);
}
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
how do i add more than one file to the dataobject
chad
|
|
|
|
|
Use a string[] array of filenames, which you should also check for if you're a drop target for the HDROP format.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
thanks for all your help
chad
|
|
|
|
|
I need to write a voice chat application in C#, but i don't how to write it. Anyone can help me? Mail me in lcsnatoo@gawab.com
Thank
|
|
|
|
|
|
what using system namespace can i find a way to tell if my computer is online? I would like to make a program that keeps checking if my computer is online. WHen i get disconnected from my 56k, i would like this program to close some applications that i will setup up, then once the computer connects (my comp redials automaticaly) the program will notice that the conection is back online and will run the applications. Im learning C# and this is the basic helpful program that i could learn to do.
all i can find are ways to have my program connect online and keep checking using my bandwidth, my very small bandwidth. is there an event that the OS throws when going online or offline that i can check?
modified 16-May-21 21:01pm.
|
|
|
|
|
As a suggestion I would use a thread to continually ping a certain website every .... 1 minute or so ? and when the ping fails you know you are not connected?
|
|
|
|