|
dybs wrote:
unsafe
{
IntPtr unmanagedArr = Marshal.AllocHGlobal(arr.Length * sizeof(int));
Marshal.Copy(arr, 0, unmanagedArr, arr.Length);
for(int i = 0; i < length; i += stepSize)
{
foo(new IntPtr(unmanagedArr.ToInt64() + i), stepSize);
}
Marshal.Copy(unmanagedArr, arr, 0, arr.Length);
Marshal.FreeHGlobal(unmanagedArr);
}
Had some time to poke around a bit more and discovered the GCHandle class. My solution is
int[] managedInput = SomeFunctionThatReturnsAnIntArray();
GCHandle arrayHandle = GCHandle.Alloc(managedInput, GCHandleType.Pinned);
IntPtr arrayPtr = arrayHandle.AddrOfPinnedObject();
long arrayAddr = arrayPtr.ToInt64();
for(int i =0 ; i < length; i += stepSize)
{
foo(new IntPtr(arrayAddr + (i * sizeof(int))), stepSize);
}
arrayHandle.Free();
Not sure if the sizeof() part works the same on 32-bit and 64-bit systems, I'll be testing that tomorrow.
What I like about this solution is that I can pass in the address I get from my GCHandle and my managed arrays is directly updated. No calls to Marshal required! Hopefully I'm not missing anything like unsafe context or fixed statment (I think the GCHandleType.Pinned takes care of that). Hope this helps other people.
Dybs
The shout of progress is not "Eureka!" it's "Strange... that's not what i expected". - peterchen
|
|
|
|
|
my programe base on WinForm.
It has two buttons,one is "start" the other is "stop".
now i click the "start" button it will excute the code as below:
public void Polling()
{
try
{
...........
Thread[] mythread = new Thread[Count];
for (int i=0; i <Count;i ++)
{
mythread[i] = new Thread(new ParameterizedThreadStart(gatherOnlineTime));
....................
mythread[i].Start(obj);
}
}
catch
{
..............
}
}
now i want to click the button of "stop" to abort the running thread.
how to do it?
Any help will be appreciated!
|
|
|
|
|
Message Closed
modified 23-Nov-14 7:04am.
|
|
|
|
|
thank you stancrm!
But the problem is how can i get the running thread's instance
when i click the other button "stop".
|
|
|
|
|
scoket wrote: Thread[] mythread = new Thread[Count];
Move this code outside the method, i.e., at the class level and use the array to access the threads from your stop method.
|
|
|
|
|
hello
my application is store the fingure print in mastercard , i used biotrust key and given sdk to store all details in mastercard., and also verification is completed . I want to read card data without a fingure verification. My client asked me , insert a card, it have a data inform the user through message
But i check the sdk not get the solution
using card ACOS3 -24
Anas
|
|
|
|
|
You're going to have to talk to the manufacturer of the SDK you're using about this. If it works liek I think it does, you can't get at the data without the print.
|
|
|
|
|
I have been looking for a plugin that generates webpages or help documents based on your content. I have found nDoc which really isn't supported anything as it doesn't even support v2.0, and SandCastle which only seems to have a plugin for Visual Studio 2005.
Well is there anything for Visual Studio 2008? I'm not having any luck finding some. I've been really bad at commenting stuff and I've read now on proper ways to do it lol.
So now I'm going back and doing it (I know, I know)
|
|
|
|
|
Any automatically generated comment is obviously useless, it represents what a piece of code could work out about your code by reading it. A human should be able to do the same. A good comment will describe something NOT clear from the code.
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|
|
And if you don't have the code...?
|
|
|
|
|
Why do you need documentation for code that doesn't exist ?
|
|
|
|
|
Because you got a DLL before the code disappeared.
|
|
|
|
|
I am commenting the code like I should be now. The problem is I am the only one that can program here. We don't really have a programming position. So if I leave they are screwed unless they happen to get a network admin that can write C# as well.
I am just trying to make it that much easier for them and was thinking a help file could help them edit small things if they need to in the future.
|
|
|
|
|
I was just running into the same thing today. Building help files that is, I commented my code properly the first time. Sandcastle with the Sandcastle Help File Builder[^] worked perfectly.
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
Perfect! That one looks great. I didn't find that version of Sandcastle.. didn't come with a GUI the one I downloaded.
Thanks Mark
|
|
|
|
|
Message Closed
modified 23-Nov-14 7:03am.
|
|
|
|
|
The files seem to be missing from that webpage
|
|
|
|
|
Hi!
I have a question. I have a DataGridView that displays some records and beside it I have another DataGridView.
How can I double click on a record in DataGridView1 so that the record appears in DataGridView2? It's basically an assignment function where I double click the records I need and they are displayd in the second gridview.
I know that I have to execute the code in the double click event of the datagridview but I have no idea how to add the selected record to datagridview2
Thank you in Advance!!
Illegal Operation
|
|
|
|
|
You'd have to read the data from the record, put it into an acceptable data source, like a list, and apply it to the second view.
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|
|
Why? What are you trying to accomplish? Are you copying data?
Anyway, I very rarely use a DataGridView, they're generally not very appropriate for production applications (they're really only good for making quick-and-dirty prototypes and demoes).
|
|
|
|
|
PIEBALDconsult wrote: they're generally not very appropriate for production applications
It's the first time I here this, why do you find it inappropriate for production applications?
|
|
|
|
|
There's usually a better way to present the data; very few applications (pretty much just spreadsheets) work well as a grid.
|
|
|
|
|
Ok, it's from a functional level, not because the control is 'bad'.
|
|
|
|
|
|
Are you using "data bound" grids or "unbound" grids?
If you're using "unbound" grids, then retrieve the selected DataGridViewRow(s) and copy them to the second grid.
If you're using "bound" grids, you should be using a typed dataset with 2 tables of the same type, and using the methods of the typed tables to retrieve the selected row(s) and adding them to the second table.
(see the grid's .SelectedRows and row .Selected properties for starters).
|
|
|
|