|
|
I have a SafeHandle returned from an external function. I want to set the "ownsHandle" property to false, but the problem is that I'm only able to do this in the constructor. Is there a way to do it?
Here is an example:
class MyHandle : SafeHandleZeroOrMinusOneIsInvalid {
MyHandle() : base(true) {}
[ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
protected override bool ReleaseHandle() {
externalReleaseHandle(handle);
}
[DllImport("MyLib.dll")] extern void externalReleaseHandle(IntPtr handle);
}
class MyClass {
public static void main(string[] args) {
MyHandle h1 = externalCreateHandle();
MyHandle h2 = externalGetPointer(h1);
}
[DllImport("MyLib.dll")] extern void externalCreateHandle();
[DllImport("MyLib.dll")] extern void externalGetPointer(MyHandle handle);
} The problem is that I want h1 to be released, but not h2 . I thought about using GC.SuppressFinalize(h2) , but still calling Dispose() would cause the same problem.
Is there a way to do this?
|
|
|
|
|
Would h2.DangerousAddRef() (without DangerousRelease() ) suffice to achieve my objective?
Many thanks to all helpful guys here in CP!
I really appreciate your help.
Know me better
|
|
|
|
|
Sorry, I noticed that this would result in a memory leak for the SafeHandle itself.
|
|
|
|
|
Hi freaks,
I've been searching in the www for a while and I didn't find any suitable implementation:
I'm searching for a "simple function" with source-code to do a ordinary kriging interpolation.
Is anybody out there, who has a function like this as c# source code?
The requirements are:
I have a a random set of points (x,y,value) inside an array (e.g. 1000x1000 coordinates(x,y,).
I want to interpolate the rest of the points.
The project is a electromagnetic field propagation.
as code:
Function List<Points> calcInterpolation(int xMax, int yMax, List<Points> samples, ParamBlock interpolationParameters)
A 2nd function would be needed, too:
Function Point calcCenterOfField(int xMax, int yMax, List<Points> samples, ParamBlock interpolationParameters)
where "samples" are the already known points, "xMax", "yMax" defines the matrix of returned values and the "interpolationParameters" holds the required params for the function
I already implemented a inverse distance weight interpolation, but this doesn't work correctly in this case.
I searched some references (GIS) and it seems, like the Kriging interpolation would be the right one.
Any idea (btw: my math knowhow doesn't include to solve matrix calculations by hand!) or any source-codes?
If there is any commercial implementation as includeable object, please give me a link But I don't want to spend thousands of Euros!
Thanks in advance
Hendrik
|
|
|
|
|
Hey Hendrik,
Even I am also trying to find a tool which could do "kriging". Did you find any? I will let you know if I come across something.
Thank you!
Anna
|
|
|
|
|
Hi,
sorry - I got nothing usable. I switched to a neural network for my application.
Hendrik
|
|
|
|
|
Hi Hendrik,
How does your neural network work? If it is possible could you share your source code, or just the dll file? Thank you very much!
Eddrick
|
|
|
|
|
I'm trying to learn async threading and I stumbled on the first piece of code. It works but with weird results. I'd be glad if you could point out what's wrong with it. Here's the code I'm trying:
private static void LongProcess(int waitTime)
{
Trace.WriteLine("LongProcess started");
Thread.Sleep(waitTime);
Trace.WriteLine("LongProcess finished");
}
private delegate void LongProcessDelegate(int waitTime);
private void Start()
{
LongProcessDelegate lp = LongProcess;
IAsyncResult ar = lp.BeginInvoke(2000, null, null);
while(!ar.Completed)
{
Trace.WriteLine("Not finished yet");
Thread.Sleep(100);
}
lp.EndInvoke(ar);
Trace.WriteLine("All completed");
}
The problem is with the results. This is what I expected:
LongProcess started
Not finished yet
..
Not finished yet
LongProcess finished
All completed
But here's the Trace log when I set it to 1000ms:
LongProcess finished
Not finished yet
..
Not finished yet
LongProcess finished
All completed
At 2000ms:
Not finished yet
LongProcess finished
Not finished yet
..
Not finished yet
LongProcess finished
All completed
What's wrong with this? Am I understanding async calls wrong?
|
|
|
|
|
kensai wrote: Am I understanding async calls wrong?
Yes. Obviously you expect the code in the LongProcess to start immediately when you call the BeginInvoke method, but that doesn't happen.
A new thread is started to run the method, and you can't predict exactly when that thread starts to run. Unless you have a multi-core processor, the thread running the LongProcess method will rarely start before you call Tread.Sleep in the main thread.
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
Alright, thanks for the info.
|
|
|
|
|
Hi,
i am new in c# an i want to write a little program.
My pgm should have a mainforms with buttons an two modules (each modules has 3 masks).
How can make this ?
Each mask as a form or
the mainform as a form and the modules as usercontrols or
the mainform as a from andmodules as panels ??
I learned the basics from books and the samples and exercises were very simple (max 2 masks/forms).
Can somebody give me links to tuts or samples about my problem.
(sorry for my english, im from germany and not so fit )
by jogi
|
|
|
|
|
I really did not understand what you mean by "Module" and "mask".
You said that you are new in C#, I have been written C# for about 5 years and I have never used these words. LOL ![Big Grin | :-D](https://codeproject.freetls.fastly.net/script/Forums/Images/smiley_biggrin.gif)
|
|
|
|
|
Hi,
i try to explain.
a mask is a window.
My Programm should have a module stockmanagement with 3 Forms/windows.
And a module suppliermanagement with 3 Forms/windows.
|
|
|
|
|
Hi everybody!
I was wondering if anybody could please help me do something. I have a text file, and inside that text file are urls along with other random junk i have written. And what I want to do is create a simple app that searches my text file for each url (http://www.url_example.com/) in the file, put that url into a string and then write that single url to another file. These text files contain over a hundred url's, sometimes more. So basically i want to make something like:
foreach (url in file("c:\\users\\jase\\desktop\\file_example.txt"))
{
streamwriter writeFile = new streamwriter("c:\\users\\jase\\desktop\\file.txt");
writeFile.Write(urlstring);
writeFile.Close
}
I'd appreciate any help i can get from anyone and thanks for takin the time to read this.
regards,
Jason Pezzimenti.
j.t.
|
|
|
|
|
I think using Regex Class[^] would help you in this.
First read the data from file, then use regex to find matches and loop through them.
The need to optimize rises from a bad design.
My articles[ ^]
|
|
|
|
|
Thanks for your help I had a look at the MSDN link you gave me and here's what I ended up using:
private void ReadFileLink_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
StreamReader ReadFile = new StreamReader("C:\\Users\\Jase\\Desktop\\File.txt");
textBox1.Text = ReadFile.ReadToEnd();
ReadFile.Close();
}
private void PerformSearchLink_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
Regex rx = new Regex(@"\b(?<word>\w+)\s+(\k<word>)\b",
RegexOptions.Compiled | RegexOptions.IgnoreCase);
string text = textBox1.Text;
MatchCollection matches = rx.Matches(text);
Streamwriter jt = new StreamWriter(C:\\Users\\Jase\\Desktop\\NEW_File.txt");
jt.Write("{0} matches found in:\n {1}" + matches.Count + text);
jt.Close();
// Report on each match.
foreach (Match match in matches)
{
GroupCollection groups = match.Groups;
textBox1.Text = ("'{0}' repeated at positions {1} and {2}" + groups["word"].Value + groups[0].Index + groups[1].Index);
}
}
However, it doesn't seem to work. At all. It never finds anything. How would I go about telling Regex to search for any URL, no matter what URL it is inside a text file? This has got me stumped.
Best Regards,
j.t.
j.t.
|
|
|
|
|
The problem is to find a good pattern: how to describe what's url and what isn't. One problem is that when you find an url inside a text, when does it stop? To the next space, punctuation char etc.
I Googled a bit and found several discussions about indentifying url. Have a look: http://www.google.com/search?hl=en&q=regex+find+url&meta=[^]
The need to optimize rises from a bad design.
My articles[ ^]
|
|
|
|
|
That was also what I was thinking "when does it stop? To the nex..." Thanks for the link I don't know what it is with me and Google, others always seem to find links that I cannot. Haha
j.t.
|
|
|
|
|
Hi
As you know System.Windows.Forms.SendKeys.Send() method has some special codes to specify keys. I want to send Left or Right shift key, but the Send method does not support it. (Send("+"))
How can I send Left/Right shift key in C#?
Any help is appreciated.
|
|
|
|
|
how can i install a converted calendar as an add-on for office 2007?
|
|
|
|
|
Hi,
Is it possible to retrieve image directly from database and displaying it in image control? If so then guide me...
modified on Saturday, November 15, 2008 3:46 AM
|
|
|
|
|
Your question is too large to answer in depth. If your problem is the datatype and the data is stored in a varbinary (or image) column, when you fetch it, you use byte array for the parameter type.
First build the basic communication between client and db. Then add varbinary column to your select statement. If you have specific problems, you should post the code that's causing the problem. This way it would be possible to answer the question.
The need to optimize rises from a bad design.
My articles[ ^]
|
|
|
|
|
of course my horse
do you want to load it to crystal reports or a form control?
check here for "load image from database", you will get many articles.
i got it from there.
nelsonpaixao@yahoo.com.br
trying to help & get help
|
|
|
|
|
I plan to distribute an application in the near future. One thing I have not been able to find thus far concerns adding code that requires a user to enter a registration key to fully enable an application. I would appreciate any guidance in this regard.
Thank you in advance.
|
|
|
|