|
Thanks a lot! This worked fine. But how about drawing in the taskbar while minimized? E.g. scrolling some text, or displaying a progress bar, etc.
|
|
|
|
|
Simple question really, does anybody know of a code driven way to get the installation path of the .NET framework without going to the registry?
post.mode = signature;
SELECT everything FROM everywhere WHERE something = something_else;
> 1 Row Returned
> 42
|
|
|
|
|
Assembly assem = Assembly.GetAssembly(typeof(System.Int32));
MessageBox.Show(assem.Location);
Charlie
if(!curlies){ return; }
|
|
|
|
|
RuntimeEnvironment.GetRuntimeDirectory();
Thank You
Bo Hunter
|
|
|
|
|
I generally don't like the Visual Studio style docking bars. I can't see any use for them in usual applications. What I would rather like to see is docking toolbars (seen first in Office 97/2000, I think) that change into floating toolbars if you drag them off the edge of screen. However, I haven't found a control like this yet (freeware I mean, there is a perfect commercial one - Xtreme Command Bars from CodeJock). Can you help me ?
|
|
|
|
|
I'm currently working on a VS.NET 2003 add-in that must intercept all the calls of "Debug.Run" command, the usual "F5". I added a delegate to BeforeExecute event like this:
Command cc=applicationObject.Commands.Item("Debug.Start", 0);
CommandEvents cev=applicationObject.Events.get_CommandEvents(cc.Guid, cc.ID);
cev.BeforeExecute += new _dispCommandEvents_BeforeExecuteEventHandler(OnBeforeExecuteHandler);
where OnBeforeExecuteHandler is a protected handler in my Connect class.
The handler is never called The add-in seems to be available, i even debugged the code above step by step and it still refuses to fire that damn event
Any idea why? Could it be something wrong with my VS ?
rechi
|
|
|
|
|
I have a dll that I need to call that expects to have *byte as a paramiter. I can do this using unsafe {} code. But the thing of it is, after I create the object FileCRC crc = new FileCRC(); and then execute an operation it dosn't clean up.
Do I somehow have to dispose of the pointer, or when it goes out of scope is it garbadge collected? The form won't close as normal unless I kill the process.
Matthew Hazlett
Windows 2000/2003 MCSE
Never got an MCSD, go figure...
|
|
|
|
|
Instead of passing byte* as the parameter, declare your parameter using either ref or out for value types (like a Byte ). This is the most common method.
For instance, if the C functions is declared like so:
void SomeFunc(byte* b); ...declare your method like so:
[DllImport("...")]
private static extern void SomeFunc(ref byte b);
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Thanks, i'll give it a try...
Matthew Hazlett
Windows 2000/2003 MCSE
Never got an MCSD, go figure...
|
|
|
|
|
Hi,
I have a VC++ COM Component that has to return array of long and array of strings to the C#. I Figure the way to do it is using SafeArrays for each of the arrays. I wanted a sample application that could return the arrays through the VC++ and then access the same arrays from the C#.
Pls I shall appreciate if some one could give a working sample.
Thanx.
Sheela
|
|
|
|
|
So long as the array doesn't contain BOTH longs and strings, you could simply use UnmanagedType.LPArray (and associated properties) in the MarshalAsAttribute that you would use on your params. If you do need a SafeArray to return from your VC++ component, then you should take a look at Array Manipulation API Functions[^] which help you create SafeArrays in VC++. You declare your parameter in VC++ as SAFEARRAY and in C# using UnmanagedType.SafeArray and an object[] array.
The documentation for SafeArrays should give you plenty of examples and since this is VC++, I don't really want to type dozens of lines for something so trivial in higher-level languages (this isn't necessary a gripe against C/C++ - which I still enjoy and appreciate - just a fact). If your function was declared like so:
void SomeFunc(SAFEARRAY arr); ...then you could declare your C# method like so:
[DllImport("the name of your DLL")]
private static extern void SomeFunc(
[MarshalAs(UnmanagedType.SafeArray)] object[] arr); There are some other things you can do as well, but you should see the documentation for the MarshalAsAttribute class and the UnmanagedType enum in the .NET Framework SDK for more information.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Hello!
I want to write a C# spider which uses multiple threads that make synchronous HttpWebRequests to different sites. The big problem is that after a while (and it's a random period of time ) the app. stops, more precisely all the Responses are TIMEOUT. The only solution seems to restart the application...some spider huh?
Other symptoms: I keep receiving a System.NullReferenceException in System.dll that I cannot catch, probably thrown by a thread from the Thread Pool (my guess);
- KeepAlive is set to false; Proxy is set by me;
- in machine.config maxconnections=100;
If I use only one thread and make one Request-Response (closing it of course) at a time it seems to work...but the one at a time approach is not what I want for my spider.
If you know something about this please help...thx!!!
|
|
|
|
|
Instead of using Thread , you should try using a ThreadPool . This limits the number of threads that run and provides additional benefits. After the application spawns so many threads, it may appear to hang because the threads clog the system and keep the app very busy.
Also, many servers limit the number of connections per client. This is commonly configured at two connections. While all those requests are waiting, they will eventually timeout because only a couple will be able to get responses.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Thx for your response!
I'm thinking about the ThreadPool alternative.
If I run the app with 4 threads, I get the same result…after a while all the Responses are TIMEOUT and it’s not meter on witch server it's try to connect. I think the # of threads it’s not a problem, I think is something else…and what about the System.NullReferenceException in System.dll that I cannot catch?
|
|
|
|
|
There could be a couple things happening. As I mentioned before, most servers limit the number of connections per client. This could cause a timeout because it won't respond to waiting requests.
Another problem is that you might not be locking your resources and are running into a dead-lock. If you have multiple threads accessing a resource, you should lock each thread so they don't access it concurrently (unless the object itself - like a synchronized Hashtable (see Hashtable.Synchronized ) - is already thread-safe. You can do this easily in C# with the lock keyword. Typically, you can pass typeof(SomeClass) to lock against with multiple threads.
As far as the NullReferenceException thrown from a thread, you can handle the Application.ThreadException event or possibly the AppDomain.UnhandleException event.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Thx again for your answer!
I’ve consider the server limitation and my threads are one request - one server design to avoid this.
About the deadlock because of an object that threads share I’ve checked and it’s not that because are threads who are finishing their job and others are created (in a limit of course). The only problem is that all receive TIMEOUT.
I’ll give you an example…
I put the spider to get me the html content of the main page for 500 sites, 5 threads maxim at a time. TIMEOUT it’s set to 20 sec. For the first 100 sites it’s work ok, in generally, only a few timeout occurred, but after that it’s bad… this timeout’s keep appearing and after 350 all the responses are timeout…
I reverse the list and it’s the same. Some times, but very rarely, I receive some response till the spider finish the 500 list, but sporadic.
I don’t now what else to do…i've tried all
|
|
|
|
|
You can't expect 500 threads to all run concurrently - the processor doesn't even allow this. You are familiar with time slices and the CPU, aren't you? Processes only get so much time. With that many threads, there's no way the CPU could service them all in a reasonable amount of time. That's why many web servers are multi-processor systems. You need to maintain better control of your threads.
If you look at the System.Threading namespace, you'll see several classes that can specify a timeout or wait indefinitely, but you should still avoid creating 500 threads. Consider designing your application so that you wait for threads to finish and then start another one. See the Threading[^] section in the .NET Framework SDK for information and examples.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
I know, I'm not that crazy to put 500 threads at a time...
I only keep 5 of them at time, when one finish the callback function it’s “--“ the counter so another can be created an start a new request.
So you see why I think that the threads are not the issue here, it's something with the way framework manage the HttpWebRequests …
|
|
|
|
|
If i create a library, and comment all public and protected members.
With the XML comments in C#.
Then the comments nicely pop up when im coding in other classes, or projects within the same solution that holds the project with the commented class.
But, when I now take the DLL, and reference not by project (not adding the project to my new solution), but by file reference, like how you would any third-party dll, the comments don't show up.
How do I tell the compiler to compile the xml comments into the dll. Or what do I have to do?
Thanks,
Kris.
|
|
|
|
|
The XML document that contains the comments must be in the same directory as the assembly you're referencing.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Consider an array of some object like ClassA. How can I quickly iterate thru this array using unsafe code and pointers? Could you please provide me a sample code?
Don't forget, that's Persian Gulf not Arabian gulf!
Murphy:Click Here![^]
Events and Delegates simplified:Click Here![^]
I'm thirsty like sun, more landless than wind...
|
|
|
|
|
I found this code:
using System;
class App {
unsafe static void Main() {
Int32[] arr = new Int32[] { 1, 2, 3, 4, 5 };
fixed (Int32* element = &arr[0]) {
for (Int32 x = 0, l = arr.Length; x <= l; x++) {
Console.WriteLine(element[x]);
}
}
}
}
I found it here[^], which I found as the first result by googling your words: "fast array iteration C# unsafe ".
- Daniël Pelsmaeker
"All e-mail I send starts with a "Hello Colin" and ends with a suitable goodbye. I get some funny looks from people who aren't called Colin, but at least it's polite."
-David Wulff
|
|
|
|
|
That's got to be the most useless code I've ever seen! Yeah, their using an unsafe context - but it's doing the same exact thing that the CLR would do in managed execution anyway. I doubt the performance payout is worth the lack of memory protection and the other problems you'll run into if this isn't run from the local machine (i.e., the MyComputer code group in reference to code access security).
Note - no offense meant to you. You simply re-posted this from a simple search result.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
If your array contains objects then the best thing to use is a for loop. Unsafe code isn't going to help much.
|
|
|
|
|
Is the object unmanaged? If not, it will be difficult. The GC is agnostic of pointers, so pointers are not allowed to reference types or structs that may appear (including structs with references) on the managed heap. If it were allowed, you could potentially wind up with heap resources referenced only by pointers that could be reclaimed while still in use.
From the language spec:
Unlike references (values of reference types), pointers are not tracked by the garbage collector - the garbage collector has no knowledge of pointers and the data to which they point. For this reason a pointer is not permitted to point to a reference or to a struct that contains references, and the referent type of a pointer must be an unmanaged-type.
An unmanaged-type is any type that isn't a reference-type and doesn't contain reference-type fields at any level of nesting. In other words, an unmanaged-type is one of the following:
sbyte, byte, short, ushort, int, uint, long, ulong, char, float, double, decimal, or bool.
The most exciting phrase to hear in science, the one that heralds the most discoveries, is not 'Eureka!' ('I found it!') but 'That's funny...’
|
|
|
|