|
Do you got an idea why th applicatoin jumps never into OnYourDelegate after calling the SetEvent(..) in the DLL?
|
|
|
|
|
// C++ code:
BOOL manualReset = false;
HANDLE theEvent = CreateEvent(NULL, manualReset, false, _T("TheEvent"));
...
SetEvent(theEvent);
...
// C# code:
event EventHandler theEventTriggered;
...
theEventTriggered += SomeHandler;
...
EventWaitHandle theEvent = EventWaitHandle.OpenExisting("TheEvent");
theEvent.waitOne();
if (theEventTriggered != null)
{
theEventTriggered();
}
Note the C++ code must execute before the C# code that creates the event handle.
If it's the other way around, then simply use
new EventWaitHandle(false, EventResetMode.AutoReset, "TheEvent"); instead of
EventWaitHandle.OpenExisting("TheEvent");
If your actions inspire others to dream more, learn more, do more and become more, you are a leader." - John Quincy Adams You must accept one of two basic premises: Either we are alone in the universe, or we are not alone in the universe. And either way, the implications are staggering” - Wernher von Braun
|
|
|
|
|
Thanks for the both answers!
@Dave
Your proposal and your code syntax ist just right! Compiles without any error and it hits my problem.
But in jumps never into OnYourDelegate after calling SetEvent(..) in the DLL.
@Ahmed
Is works fine, but if I did correctly understand, there's has to be a thread permenently running in the background to check up the call of the event!? When the event in the DLL raises, my own event 'theEventTriggered' is called from the thread.
It works fine, but I want to raise the Event in the C# code like an interrupt out of the DLL. Without permanently checking in a own thread. You see a possibility there?
I thought, I can give the DLL the adress of my C# event oder delegate. So, when the event in the DLL is fired, my event in C# is also fired. Like in the following way:
[DllImport("kernel32.dll", SetLastError = true, CallingConvention = CallingConvention.Winapi, CharSet = CharSet.Auto)]
public static extern IntPtr CreateEvent
(
IntPtr lpEventAttributes,
bool bManualReset,
bool bIntialState,
string lpName
);
public delegate void DoHandler();
public void Foo()
{
IntPtr EventsAdress = CreateEvent(IntPtr.Zero, false, false, "TheEvent");
DoHandler doH = new DoHandler(MethodForEventAction);
doH = (DoHandler)Marshal.GetDelegateForFunctionPointer(EventsAdress, typeof(DoHandler));
SetClientParam(wParam, EventsAdress );
}
public void MethodForEventAction()
{
Console.WriteLine("Event from DLL raised.");
}
SetEvent(EventsAdress);
Thanks for your input! Your suggestions are very useful. Do you got any idea about my second post?
|
|
|
|
|
Yes, you are correct that there needs to be a thread in the C# code waiting on the native kernel event to be triggered. That thread would then trigger the C# event or call the C# method. Note that the event or method would run in the context of the waiting thread.
You don't need to pass the event handle over to the C++ code or DLL. You just need to call CreatEvent with the same parameters and it will get a handle to the same event. Events created with CreateEvent are global to the system, and potentially accessible from any process.
If your actions inspire others to dream more, learn more, do more and become more, you are a leader." - John Quincy Adams You must accept one of two basic premises: Either we are alone in the universe, or we are not alone in the universe. And either way, the implications are staggering” - Wernher von Braun
|
|
|
|
|
Thank you very much. It works.
IntPtr MsgReceivedEvent
MsgReceivedEvent = CreateEvent(IntPtr.Zero, false, false, "RcvEvent");
startRcv((uint)MsgReceivedEvent);
EventWaitHandle theEvent = EventWaitHandle.OpenExisting("RcvEvent");
while (!PendingCancel)
{
if (theEvent.WaitOne(5000))
{
Log("EVENT RAISED!");
}
}
SetEvent(MsgReceivedEvent);
|
|
|
|
|
Excellent! Glad I could be of help!
If your actions inspire others to dream more, learn more, do more and become more, you are a leader." - John Quincy Adams You must accept one of two basic premises: Either we are alone in the universe, or we are not alone in the universe. And either way, the implications are staggering” - Wernher von Braun
|
|
|
|
|
Hi
I want to highlight or more like select all the occurrences of a word. But I have googled a lot and haven't found anything about that.
When I have tried, it just selects one appearance of the word, the last.
Word.Application ap = new Word.Application();
doc = ap.Documents.Open(path, ReadOnly: false, Visible: true);
ap.Selection.Find.ClearFormatting();
ap.Selection.Find.Text = txtFind.Text;
ap.Selection.Find.Execute();
while (ap.Selection.Find.Found)
{
ap.Selection.Select();
ap.Selection.Find.Execute();
}
doc.Activate();
ap.Visible = true;
ap.ActiveWindow.SetFocus();
I have tried so many different approaches, but haven't been able to solve it.
I don't want to highlight the words, I just want them to be selected as they are when you choose find all in Microft Word.
Hope somebody can help me.
Many thanks
Fia
|
|
|
|
|
You are missing some properties for your Selection.Find list. Try setting Forward = true and Wrap = wdFindContinue . To find these values, you can use the macro recorder in Word and perform a Find all operation - this should give you a good place to start.
|
|
|
|
|
Hi
Thanks for your reply, but I have already tried that, but nothing changes. It just selects the last occurrence of the word. I really don't want to use a macro. Aren't there another way to accomplish this.
Many thanks
Fia
|
|
|
|
|
Use the macro to tell you what options to set, not to actually run the find.
|
|
|
|
|
Hi
Thank you, that was smart. But when I record a macro that does what I want and later tries to run the macro nothing happens. I don't understand why?
Do you have anymore suggestions.
Many thanks
Fia
|
|
|
|
|
fiaolle wrote: It just selects the last occurrence of the word.
May be you have to set MultiSelect = true somewhere in your code. Just a suggestion though, I haven't done Word automation so far.
|
|
|
|
|
Repeating what was already said....
1. Create a macro that does what you want.
2. LOOK at the macro. Figure out what it is doing.
3. Use the information that you LEARNed in 2 to create your C# code.
|
|
|
|
|
Hi
I have already tried that but it doesn't work. I have no idea how to solve this. If anyone knows please help.
Thanks
Fia
|
|
|
|
|
Is there a way to run nunit Test class 50 times in a loop ?
For example I have a class like
[TestFixture]
public class DemoFailureTeste
Can I run it 50 times successively ?
modified 10-Oct-11 7:11am.
|
|
|
|
|
Of course you can. Just move the code that you want testing into a for loop. I would probably move it into a method on its own and just call that from the loop if I were you.
|
|
|
|
|
But it will recall the methods only , right ? I need to reload the class itself .Any idea ?
|
|
|
|
|
What are you trying to achieve? There is no inbuilt way to run the tests n times, so you'd end up having to code for this yourself.
|
|
|
|
|
Yeah , I was looking for some inbuilt attributes.There are no such attributes.I am getting an intermediate failure.So need to figure it out.
|
|
|
|
|
You could always write a quick test harness console application, load the class in and look for methods that have this attribute associated with them. It's fairly trivial to execute them once you have this info.
|
|
|
|
|
You could try Microsoft.VisualStudio.TestTools.UnitTesting.DataSourceAttribute.
I use it to run my test with different testdata:
[DataSource("Microsoft.VisualStudio.TestTools.DataSource.XML",
"|DataDirectory|\\MyDataSource.xml",
"Row",
DataAccessMethod.Sequential)]
|
|
|
|
|
buchstaben wrote: You could try
Microsoft.VisualStudio.TestTools.UnitTesting.DataSourceAttribute. I
use it to run my test with different testdata:
[DataSource(<SPAN class=code-string>"</SPAN><SPAN class=code-string>Microsoft.VisualStudio.TestTools.DataSource.XML"</SPAN>,
<SPAN class=code-string>"</SPAN><SPAN class=code-string>|DataDirectory|\\MyDataSource.xml"</SPAN>,
<SPAN class=code-string>"</SPAN><SPAN class=code-string>Row"</SPAN>,
DataAccessMethod.Sequential)]
I really can't see how this helps the OP. The question specifically asks about NUnit, and he hasn't asked how to associate a datasource with his test; the question asks how to run the same test class multiple times.
|
|
|
|
|
you're right. haven't seen the n in "nunit"..
nevertheless using (nearly empty) datasource is a way to achieve multiple testruns -> should work with nunit as well.
|
|
|
|
|
Bad idea.
The point of unit test is to verify that the code works. That isn't your goal here.
So what you need to is the following.
1. Create some code that demonstrates the failure. NOT a unit test itself but it certainly as a method that is suitable for use in a unit test.
2. Create a unit test that calls the code of 1.
3. Figure out the bug by running 2.
4. Re-write 1/2 as necessary to insure that the unit test run will verify, now and in the future, that your code works and continues to work.
By the way intermittent failures are often due to threads. So if you don't have any unit tests that test threading you need to add those.
|
|
|
|
|
Hi
I want a good code(log in )
thanks
|
|
|
|