|
Thanks so much,.
I am gonna try it and see what it would result into.
But.. Do you think there may be a better idea than the one I came up with.
Please enlighten my brain man.
Thank you....
|
|
|
|
|
Hello,
I'm needing write some Java/C# interop code and I'm wondering if anyone here has experience in this area and could provide a few tips.
I understand there are tools that allow you to register Java components as COM objects. This allows you to solve the problem with COM interop. Is this the best way to go? Are there any other great ideas?
Thanks!
|
|
|
|
|
This whole multi-threading structure keeps shifting in and out of focus like a Dali painting after 5 pints of Guinness...
Okay, I have the following going in my OldMcDonald process:
PanickyChicken chickenLittle = new PanickyChicken();<br />
<br />
Thread t = new Thread(new ThreadStart(chickenLittle.WanderAbout));<br />
t.Start();<br />
while ( !t.IsAlive );<br />
<br />
this.WaitForAcornToDrop();<br />
...
Now, once the WaitForAcornToDrop method has executed, I want to get my chickenLittle thread (t) to execute its WarnAll method [e.g. chickenLittle.WarnAll("The sky is falling");]
How do I tell an executing thread to perform a task?
Clive Pottinger
Victoria, BC
|
|
|
|
|
Hi,
a thread executes whatever code is passed to it at creation time, in your example it will run
the WanderAbout() method until that method is done. So whatever you wnat the thread to do must be
inside that method, you can't make it suddenly do something completely different.
Luc Pattyn [Forum Guidelines] [My Articles]
This month's tips:
- before you ask a question here, search CodeProject, then Google;
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get;
- use PRE tags to preserve formatting when showing multi-line code snippets.
|
|
|
|
|
In addition to what Luc said, you can influence what's happening inside your thread's procedure for example by setting properties of your object which in turn are used inside the thread procedure.
For example, your PanickyChicken class could have a property
public bool ThinksSkyIsFalling = false {get; set;} (don't know if that's the correct C# 3.5 syntax, but I think you get the idea).
Now your chicken is wandering about until your program tells it that the sky is falling:
chickenLittle.ThinksSkyIsFalling = true; Now inside your WanderAbout method you can execute the WarnAll method as soon as ThinksSkyIsFalling==true and then exit WanderAbout - chickenLittle's job is done.
But then you'll have to think about synchronization issues. In the example above I think there's not much that can go wrong without explicit synchronization, but when you're performing operations that can be interrupted by a thread switch, you'll definitely have to take care of these cases. The lock() instruction can come handy in these cases.
Regards,
mav
--
Black holes are the places where God divided by 0...
|
|
|
|
|
Thanks Mav.
I think you hit the root of my question - is a reference, in my main thread, to chickenLittle.ThinkSkyIsFalling valid even though chickenLittle is operating in thread t ? It appears it is - great.
That gives me the groundwork I needed to get information to my executing thread.
Thanks again.
Clive Pottinger
Victoria, BC
|
|
|
|
|
Hi.
I have a problem in XNA; it's that I want to have several sprites of the same thing, except place them in different places while keeping the 'physics' they all have. Can anyone give me a general idea of how I might do this. (Please try not to be too technical, unless it's needed!) If it helps anyone understand better, I'm making a border around the edge of the form with the boxes, but then I also want to draw 5 more inside various places. Please help, thanks!
+I tried making the Texture2D into an Array and in the Load method, making a for loop to load a certain amount, but that doesn't work. That was my idea... Partly... Help is still appreciated.
+Actually, I'vr got the hang of it. Stupid mistake... But any more info would still be liked. Thanks, kind of.
- I love D-flat!
modified on Tuesday, January 22, 2008 6:01:45 PM
|
|
|
|
|
Glad to hear you figured it out.
In future it would be better if you posted your XNA related questions here.
You will get much quicker and better answers - mainly because the guys/girls who wrote the XNA framework maintain, and actively contribute to the forum.
Cheers,
Mark.
|
|
|
|
|
How do I go about playing 24-bit wav files? I have 8 and 16 bit wavs playing fine with directsound, but when I run a 24-bit file through the same code I get a not-so-helpful crash ("Value does not fall within the expected range.") when trying to create a new SecondBuffer instance (sound = new SecondaryBuffer(dataGridResults.CurrentRow.Cells[3].Value.ToString(), d, dSound);).
I have searched high and low for answers, but the most I can come up with is something to do with WAVEFORMATEX or WAVEFORMATEXTENSIBLE. Although I don't know how to go about using them.
|
|
|
|
|
I have a C# solution with 2 projects, a test form in one project and a DLL in another. The DLL connects to a socket and sends and receives messages to and from the test application using properties in the DLL.
How does one send an event, such as poll events of the socket, to the test application? I want to know if the connection was dropped, when it was dropped, and set a button to red when connection is lost.
Very new to C# and I hope I framed the question well enough to get an answer.
Thanks in advance,
Joe
|
|
|
|
|
Hi All,
I can create appointments in MS Outlook via my c# application, bud how can i now remove or update this appointments?
thanx
|
|
|
|
|
Hello,
I am developing in C#.net 3.0 and here, i am using the multi-threading. Here i have 5 threads in the following way:
One thread sleeps for x mins after completing its one iteration.
Second thread sleeps for y secs after completing its one iteration.
Third thread sleeps for x hours after completing its one iteration.
Fouth thread sleeps for 1 day after completing its one iteration.
And the fifth thread sleeps for r mins after completing its one iteration.
All these threads have access to same database tables, sometimes they do reading and sometimes they do writing into the database table.
1) Here, I have an idea that, i have to lock the database.
2) And also, while debugging i have seen that, due to multi-threading there is an issue with the order of execution.
Can anyone help me on this ..please.... everything is over and at the last minute.. this problem arised.
Thanks
Anee
Anee
|
|
|
|
|
I don't know what your question is. You described a system, but the only problem that I can discern from your post is that
anumadhu wrote: there is an issue with the order of execution.
This is much too vague for me to offer any advice. Please post a specific question and we will try to help.
Sounds like somebody's got a case of the Mondays
-Jeff
|
|
|
|
|
How to Compare two Stringsand to copy string into other string using C# Code.
What is the syntax?
Is there any system defined function such as strcmp,strcpy as used in C
I am taken two values in strings ,
now I want to compare which one is greater.
I can do it treating values as int or to convert.ToInt32,
but requirement is to treat and compare them as strings.
|
|
|
|
|
simworld wrote: Is there any system defined function such as strcmp,strcpy as used in C
To compare 2 strings, you could use the String.Compare method.
To copy one string value into another, all you do is
<br />
string oldValue = "OldValue";<br />
string newValue = oldValue;<br />
|
|
|
|
|
|
There are several ways you can compare strings in C#. The simplest way is to just test using equality:
string a = "This is a test";
string b = "This is another test";
if (a == b) {
} However, this will do a case-sensistive, culture-sensitive compare which may not be what you want and isn't necessarily the most performant test.
The closest methods to strcmp in C# are going to be the String.Compare , String.CompareOrdinal or the String.CompareTo methods.
In order to copy a string, you can simply copy it. Strings in C# are immutable, so you will always get a new instance of the string:
string a = "This is a test";
string b = a; You can find all of the string methods here[^].
Scott.
—In just two days, tomorrow will be yesterday.
—Hey, hey, hey. Don't be mean. We don't have to be mean because, remember, no matter where you go, there you are. - Buckaroo Banzai
[ Forum Guidelines] [ Articles] [ Blog]
|
|
|
|
|
|
I have read about how to send parameters to an application at runtime but what if the program is all ready running? Here is where I am stuck...
1. Run my application to get it into taskbar.
2. Click on a special hyperlink to send a parameter to this application.
I have learned how to create a registry entry to launch my application when a link is launched. Here are the problems..
1. I don't want my app to run again if the link is clicked again.
2. I need to link to continue to get parameters as the links get clicked
Any help here would be great.
|
|
|
|
|
|
Hi..
I have a vc++ dll that returns a Bstr that i need to read out in c# the dll is called like (at the moment)
[DllImport("myDLL.dll")]
[return : MarshalAs(UnmanagedType.BStr)]
private static extern string Getbstr();
i have tryed
string tmp = Marshal.PtrToStringBSTR(Getbstr());
pvarData="02" + tmp;
etc.. but only seam to get garbage.. can anyone help me or point me to a web site that explains the formats bstr etc...or how to convert them.
many thanks
calvin
P.S please be kind i have only just learnt c++ and the dll returns a bstr as it is also shared with vb apps...
|
|
|
|
|
Calvin Streeting wrote: [DllImport("myDLL.dll")]
[return : MarshalAs(UnmanagedType.BStr)]
private static extern string Getbstr();
Where did you get your import statement from?
led mike
|
|
|
|
|
the dll is declared as in vc6++
MYDLL_API BSTR __stdcall getbstr();
So i googled and people were mentioning "MarshalAs" which seameed to complie fine, is there another way (hopefully without changing the dll)
many thanks
calvin
|
|
|
|
|
Calvin Streeting wrote: the dll is declared as in vc6++
MYDLL_API BSTR __stdcall getbstr();
So the C module is allocating the BSTR. How is the deallocation handled?
Calvin Streeting wrote: have tryed
string tmp = Marshal.PtrToStringBSTR(Getbstr());
Did you try
string tmp = Getbstr();
led mike
|
|
|
|
|
Hi... I think i got it now..
here is a more complete code...
vc++ dll
//----------------------------------------------
//header
SSFILEDLL_API BSTR __stdcall GetEmailSubject();
SSFILEDLL_API BSTR __stdcall GetEmailData(char *szString);
//----------------------------------------------
//code
SSFILEDLL_API BSTR __stdcall GetEmailSubject(){
return GetEmailData("__substg1.0_0037001E");
}
SSFILEDLL_API BSTR __stdcall GetEmailData(char *szString){
BSTR Message;
COleStreamFile osf;
if (myCSS.OpenStream(szString, osf)) {
DWORD dwLength = osf.GetLength();
LPSTR buffer=(LPSTR)_alloca(dwLength+1);
osf.Read(buffer,dwLength);
buffer[dwLength]='\0';
Message = SysAllocStringByteLen(buffer, lstrlen(buffer));
return Message;
}
else {
char *buff = "False";
Message = SysAllocStringByteLen(buff, lstrlen(buff));
return Message;
}
}
and then in c#
I used
//----------------------------------------------
//header
[DllImport("ssFileDLL.dll")]
private static extern IntPtr GetEmailSubject();
IntPtr ptr = GetEmailSubject();
string s = Marshal.PtrToStringAnsi(ptr);
if (s!="False")
pvarData="" + s;
else
pvarData="";
and that seems to work... the code is a two part affair.. the first vc++ dll deals with outlook msg files parsing them and getting the mapi properties...
the second part is a explorer shell extention that shows the mapi properties for folders that contain archived (saved out of outlook) folders containing msg files...
after a bit of frigging around i now have form,to,subject,attachment count, and i am working on the sent/recived date... that are returned as a FILETIME
so onward i march and many thanks for your help...
calvin
ps any comments on code are always apreciated as i am new to the language (vb is far mote forgiving than c,c#,c++ etc...)
|
|
|
|