|
jdunlap wrote:
You'd think I'd learn...
[humble] It's what makes us human.....[humble]
Nick Seng (the programmer formerly known as Notorious SMC)
God, I pity me! - Phoncible P. Bone
|
|
|
|
|
How do I put my program at the top of the process priority?
/\ |_ E X E GG
|
|
|
|
|
Process curProcess = Process.GetCurrentProcess();
curProcess.PriorityClass = ProcessPriorityClass.High;
Mind you, you have got to be very careful about what you do with this. You could find yourself with a totally unresponsive system. In general, messing about with priorities to give your app more oomph is only masking a deeper problem.
Cheers, Julian
Program Manager, C#
This posting is provided "AS IS" with no warranties, and confers no rights.
|
|
|
|
|
By default without messing with anything, what is the process priortiy set at?
and is this using
using System.Threading;
???
|
|
|
|
|
eggie5 wrote:
By default without messing with anything, what is the process priortiy set at?
Normal.
And you're using the System.Diagnostics namespace. The difference between setting thread priority and setting process priority is that setting it at process level changes the priority of all threads within the current process...whereas setting thread priority sets the level of only the current thread...other threads in the same process would remain unchanged.
I have also lived some years in Spain, and there people don't accept that you speak bad spanish. I usually compensate by speaking loud and accusing people of being stupid because they don't understand me. It usually works quite well.
-jhaga on non-native languages
|
|
|
|
|
I know this is off-topic, but where would I go to make suggestions for the improvement of C# and the .NET Framework?
"Blessed are the peacemakers, for they shall be called sons of God." - Jesus
"You must be the change you wish to see in the world." - Mahatma Gandhi
|
|
|
|
|
I am using the following to open and write and encryped datafile.
FileStream fout = new FileStream(OptionsDataFile, FileMode.Create, FileAccess.Write);
TripleDESCryptoServiceProvider tdes = new TripleDESCryptoServiceProvider();
CryptoStream encStream = new CryptoStream(fout, tdes.CreateEncryptor(new byte[] {22,184,62,104,66,100,202,17,91,254,197,181,224,62,36,138,128,227,146,111,134,83,241,125}
,new byte[] {216,237,102,42,142,11,133,104,}),
CryptoStreamMode.Write);
ASCIIEncoding AE = new ASCIIEncoding();
and the following to decrypt.
FileStream fin = new FileStream(OptionsDataFile, FileMode.Open, FileAccess.Read);
TripleDESCryptoServiceProvider tdes = new TripleDESCryptoServiceProvider();
CryptoStream encStream = new CryptoStream(fin, tdes.CreateDecryptor(new byte[] {22,184,62,104,66,100,202,17,91,254,197,181,224,62,36,138,128,227,146,111,134,83,241,125}
,new byte[] {216,237,102,42,142,11,133,104,}),
CryptoStreamMode.Read);
ASCIIEncoding AE = new ASCIIEncoding();
int tempByte = new int();
byte[] inBytes = new byte[(int)fin.Length];
encStream.Read(inBytes,0,(int)fin.Length);
When it gets to the read I get the following.
An unhandled exception of type 'System.Security.Cryptography.CryptographicException' occurred in mscorlib.dll
Additional information: Bad Data.
Anyone have any ideas why. Everything is the same for the write. I just do not get why the data would be bad.
|
|
|
|
|
Not sure what's going on for you. Maybe it's something in the code you *don't* show <g>.
The following works just fine for me (I separated out the creation of some the objects into separate statements for readability):
class Class1 {
static void Encrypt(string inputFile, string outputFile) {
FileStream fsin = new FileStream(inputFile, FileMode.Open, FileAccess.Read);
FileStream fsout = new FileStream(outputFile, FileMode.Create, FileAccess.Write);
byte[] key = new byte[] {22,184,62,104,66,100,202,17,91,254,197,181,224,62,36,138,128,227,146,111,134,83,241,125};
byte[] iv = new byte[] {216,237,102,42,142,11,133,104};
TripleDESCryptoServiceProvider tripleDes = new TripleDESCryptoServiceProvider();
ICryptoTransform t = tripleDes.CreateEncryptor(key, iv);
CryptoStream cs = new CryptoStream(fsout, t, CryptoStreamMode.Write);
int len = (int) fsin.Length;
byte[] buffer = new byte[len];
len = fsin.Read(buffer, 0, len);
cs.Write(buffer, 0, len);
cs.Close();
fsout.Close();
fsin.Close();
}
static void Decrypt(string inputFile, string outputFile) {
FileStream fsin = new FileStream(inputFile, FileMode.Open, FileAccess.Read);
FileStream fsout = new FileStream(outputFile, FileMode.Create, FileAccess.Write);
byte[] key = new byte[] {22,184,62,104,66,100,202,17,91,254,197,181,224,62,36,138,128,227,146,111,134,83,241,125};
byte[] iv = new byte[] {216,237,102,42,142,11,133,104};
TripleDESCryptoServiceProvider tripleDes = new TripleDESCryptoServiceProvider();
ICryptoTransform t = tripleDes.CreateDecryptor(key, iv);
CryptoStream cs = new CryptoStream(fsout, t, CryptoStreamMode.Write);
int len = (int) fsin.Length;
byte[] buffer = new byte[len];
len = fsin.Read(buffer, 0, len);
cs.Write(buffer, 0, len);
cs.Close();
fsout.Close();
fsin.Close();
}
static void Main(string[] args) {
Console.WriteLine("Starting encryption...");
Encrypt(@"c:\test.txt", @"c:\test.enc");
Console.WriteLine("...done");
Console.WriteLine("Starting decryption...");
Decrypt(@"c:\test.enc", @"c:\test.dec");
Console.WriteLine("...done");
Console.ReadLine();
}
}
Cheers, Julian
Program Manager, C#
This posting is provided "AS IS" with no warranties, and confers no rights.
|
|
|
|
|
The problem with the orginal code is I was not Seeking to the beginning of the stream.
|
|
|
|
|
I'm borrowing some code from Pavel's Command Prompt Explorer Bar installer to use in my own explorer bar's installer.
Recently I've been thinking that using an assembly version like "1.0.*" (hence, for example, "1.0.1304.25935") would be useful, at least for development and debugging purposes. (Someone please point out the cons to this idea!)
Well, anyway, Pavel's installer basically exists to register the assembly, and unregister the assembly at uninstallation. So it all comes down to getting the relevant assembly so it can be fed to RegistrationServices.RegisterAssembly().
Currently the code for getting the relevant assembly looks like this:
Assembly VisITBarAssembly
{
get
{
return AppDomain.CurrentDomain.Load("VisIT, Version=1.0.0.0, Culture=neutral, PublicKeyToken=4d504ee06f99380a");
}
}
This works because the version is hardcoded to "1.0.0.0" in Installer.cs as well as AssemblyInfo.cs. I'd like to remove this string from Installer.cs so I can only worry about AssemblyInfo.cs whenever I want to bump up a version number. (Bonus points if I could remove the need to change both AssemblyInfo.cs and the version number in the Setup project! Additional bonus points if I can access the Setup project's "Manufacturer" etc. fields from the application, but I guess the best (or only?) solution would be to use the Registry.)
So what are some good ways to go about this? I think using the Registry might be one way to go about it, having to store the assembly's full name somehow (programmatically) in a registry entry. Personally I think it would be nicer to avoid it, but hey! If I assume a constant GUID, then I could look it up in the registry (it's already stored there, but then again, this might implicitly get stored from the RegisterAssembly call).
It would be even nicer, I think, to have a dynamic GUID, that allows the GUID to change with the Product GUID (set in the Setup project), but I don't know if that's feasible.
And furthermore, what can I do with the savedState object that is an argument to so many Installer event handlers?
Any tips, comments, or smooth suggestions?
Thanks,
Arun
|
|
|
|
|
Alright,
I have some source code libraries that help me convert text into pdf417 (2d) barcodes. That all works fine. Heres my issue, the
public sbyte[]createbarcode() method gives me an array of sbytes with which to create a bitmap. I want to then print this bitmap. My question is, are there any gdi junkies out there who can point me in the right direction as far as creating a bitmap through a big old sbyte array?
Thanks for the help in advance,
Ryan
|
|
|
|
|
System.IO.MemoryStream stream = new System.IO.MemoryStream(b, true);
stream.Write(bytes, 0, bytes.Length);
Bitmap bmp = new Bitmap(stream);
|
|
|
|
|
I would really need some help with using the WIN32 API SendMessage() from C#. I want to start a program from mine, but if it's already an instance open, I wanna find that window and send it a message of a file to load instead of starting a second instance.
I'll do this through the FindWindow and OpenIcon methods, but how do I send my message to the other window?
I know how to get my own message ID's and so my second application will listen for a specific custom message, but how do I send the actual data to it? I've found something called COPYDATASTRUCT or something, but how to use it? and from C#
I'd really appreciate some help I haven't done any windows programming before and it's kind of a Jungle of structs and defines =) And on top of that the Marshal-As-issues...
have a nice day i'd appreciate some help on this one. really.
|
|
|
|
|
I now know that i should use WM_COPYDATA together with a COPYDATASTRUCT. but how do I get something corresponding to a pointer from my object, to pass as lpData in the struct?
I guess that's my main question really. And also what types to use.
|
|
|
|
|
[DllImport("user32.dll", CharSet=CharSet.Auto)]
private extern static int SendMessage(IntPtr hwnd, int msg, int wParam, ref COPYDATASTRUCT lParam);
[StructLayout(LayoutKind.Sequential)]
struct COPYDATASTRUCT {
int dwData;
int cbData;
IntPtr lpData;
}
COPYDATASTRUCT cds=new COPYDATASTRUCT;
cds.cbData=Marshall.SizeOf(data);
IntPtr mem=Marshall.AllocHGlobal(cds.cbData);
cds.lpData=Marshall.StructureToPtr(data,mem,true);
cds.lpData=mem;
[DllImport("user32.dll", CharSet=CharSet.Auto)]
private extern static int SendMessage(IntPtr hwnd, int msg, int wParam, void* lParam);
COPYDATASTRUCT cds=new COPYDATASTRUCT;
SendMessage(handle,WM_COPYDATA,wParam,(void*)&cds);
"Blessed are the peacemakers, for they shall be called sons of God." - Jesus
"You must be the change you wish to see in the world." - Mahatma Gandhi
|
|
|
|
|
thanks very much, this helped me a lot. Kind of you to find the time helping me.
have a good one!
|
|
|
|
|
misterbear wrote:
thanks very much, this helped me a lot.
BTW, I made a mistake:
The line:
cds.lpData=Marshall.StructureToPtr(data,mem,true);
should be:
Marshall.StructureToPtr(data,mem,true);
"Blessed are the peacemakers, for they shall be called sons of God." - Jesus
"You must be the change you wish to see in the world." - Mahatma Gandhi
|
|
|
|
|
You'll find a Win32Window class on www.csharp.net in the code section that will do the FindWindow part for you.
|
|
|
|
|
|
You're right.
"Blessed are the peacemakers, for they shall be called sons of God." - Jesus
"You must be the change you wish to see in the world." - Mahatma Gandhi
|
|
|
|
|
|
I've been doing some testing with the HttpWebRequest object returned from WebRequest.Create(sURL) method and found that the timeout property is not very precise.
It often times out after more than twice the value I set. For example it takes about 30 seconds for a timeout value of 15000. I’ve seen it take 15 seconds for a value of 5000.
Plus or minus a few seconds I could let slip but what might be the reason for more than doubling the timeout value?
(I tested the timeout by turning the power off to my cable modem. My computer is connected to the modem through a router which I left on.)
|
|
|
|
|
Is this happening in a separate thread? How many threads might there be running simultaneously?
|
|
|
|
|
I've been doing all my tests in a new "test" solution right in the constructor of Form1. So its only one thread. hmmm.... I wonder if its the debugger that is causing this. I will have to test it in a Release version.
|
|
|
|
|
Certainly try it outside of the debugger ("Start Without Debugging"). A Release build shouldn't be necessary, but it would be interesting if it did...
|
|
|
|
|