|
Hello!
How do CancelEventHandler s work? I think the delegates get called in a random order. What if the first delegate in the chain sets the Cancel property to true, but the second one resets it to false? Will the caller (i.e. the one who sent the event) get true or false in this case?
Best regards
Dominik
_outp(0x64, 0xAD);
and
__asm mov al, 0xAD __asm out 0x64, al
do the same... but what do they do??
(doesn't work on NT)
|
|
|
|
|
Dominik Reichl wrote: How do CancelEventHandlers work? I think the delegates get called in a random order. What if the first delegate in the chain sets the Cancel property to true, but the second one resets it to false? Will the caller (i.e. the one who sent the event) get true or false in this case?
You are correct Each 'handler' would have to check if the value is already set or not, decide on some policy how you will handling that. Obviously, if someone else attaches to it too, you will have no control.
A better way would be to make your own 'CancelEventArgs', eg:
class CancelEventArgs
{
bool cancel = false;
public bool Cancel
{
get {return cancel;}
set {if (!cancel) cancel = value;}
}
}
This way you can gaurentee, once cancelled, it cant be uncancelled.
|
|
|
|
|
I'll do it like that, thanks!
_outp(0x64, 0xAD);
and
__asm mov al, 0xAD __asm out 0x64, al
do the same... but what do they do??
(doesn't work on NT)
|
|
|
|
|
You could also do something like this:
public class TestCancellableEvents
{
public static void Main()
{
TestClass test = new TestClass();
test.MyEvent += new MyDelegate(test_MyEvent);
test.MyEvent += new MyDelegate(test_MyEvent2);
test.doit();
}
void test_MyEvent2(object sender, CancelEventArgs args)
{
}
void test_MyEvent(object sender, CancelEventArgs args)
{
args.Cancel = true;
}
public class CancelEventArgs
{
bool cancel = false;
public bool Cancel
{
get { return cancel; }
set { cancel = value; }
}
}
public delegate void MyDelegate(object sender, CancelEventArgs args);
public class TestClass
{
public event MyDelegate MyEvent;
public void doit()
{
Delegate[] list = MyEvent.GetInvocationList();
CancelEventArgs args = new CancelEventArgs();
foreach (MyDelegate handler in list)
{
handler(this, args);
if (args.Cancel)
{
break;
}
}
}
}
Vitaliy Tsvayer
Tikle
|
|
|
|
|
Vitaliy Tsvayer wrote: Delegate[] list = MyEvent.GetInvocationList();
You sure that doesnt return multicast delegates? Good approach
|
|
|
|
|
Well,
public MyDelegate MyEvent;
is actually compiled as following:
private MyDelegate MyEvent;
[MethodImpl(MethodImplOptions.Synchronized)]
public void add_MyEvent(MyDelegate value)
{
this.MyEvent = (MyDelegate) Delegate.Combine(this.MyEvent, value);
}
[MethodImpl(MethodImplOptions.Synchronized)]
public void remove_MyEvent(MyDelegate value)
{
this.MyEvent = (MyDelegate) Delegate.Remove(this.MyEvent, value);
}
that is evet keyoword in c# creates methods to manage multicast delegate.
And the following:
class1.MyEvent += new MyDelegate(this.test_MyEvent);
is simply a call to the add_MyEvent() method.
And finally GetInvocationList() method is defined in MSDN as below:
"Returns an array of delegates representing the invocation list of the current delegate.
Each delegate in the array represents exactly one method.
The order of the delegates in the array is the same order in which the current delegate invokes the methods that those delegates represent."
Vitaliy Tsvayer
Tikle
|
|
|
|
|
Thanks for the MSDN snippet. Never seen or noticed that, or maybe they added it later. It's good info to know.
|
|
|
|
|
how to compare two files in c#
tahir
|
|
|
|
|
It really depends on what those two files are. If it is a simple binary comparison then you open a file stream for each file and go through both files byte by byte comparing them. Since simple binary comparisons are, for the most part, fairly useless methods of comparison you might want to tell us the file type.
|
|
|
|
|
How do i add a Tab space programatically like you add comma to string.
Suppose i have something like Mike Bond
I want to add tab space between Mike and Bond
i.e Mike Tab Space Bond
|
|
|
|
|
"Mike\tBond"
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook www.troschuetz.de
|
|
|
|
|
mystring += "\t"
regards
modified 12-Sep-18 21:01pm.
|
|
|
|
|
i want to make C# application that can search to any statment and then replace this statment
how can make my application will print this word file
finaly i dont want to make save to any change at this file ( close file without save)
Palestine
|
|
|
|
|
Hello
TAREQ F ABUZUHRI wrote: i want to make C# application that can search to any statment and then replace this statment
That's possible through COM interop. Just make a reference to "Microsoft Word Object Library" in the COM tab. This implies that Microsoft Word should be installed on your machine AND the user's machine for this to work.
Search your MSDN for "Microsoft Word Interop" for more info
TAREQ F ABUZUHRI wrote: how can make my application will print this word file
Same as the above.
TAREQ F ABUZUHRI wrote: finaly i dont want to make save to any change at this file ( close file without save)
Make it readonly, or when the changes event is fired -Don't know its name - Make sure to check if it's from the user or your replacer. If the user made those changes, cancel them.
If you can't get through MSDN with that, just repost.
Regards
|
|
|
|
|
do u have any example code to do this ....
Palestine
|
|
|
|
|
|
Hi all
i was coding from one pc which has Excel 2000 Installed and i was successful in interfacing with c# ... but when i try to run the same in another pc with Excel 97 , it fails . Gives a runtime error ...
is it not compatible with 97?
how can i ressolve this issue ??
Thanks
Akhil
|
|
|
|
|
AnnnS wrote: how can i ressolve this issue ??
Upgrade excel. 97 is almost 10 years old after all...
|
|
|
|
|
Install the dll used for 97
It would be best to use reflection to late bind to it
--------------------------------------------------------
1 line of code equals many bugs. So don't write any!!
My mad coder blog
|
|
|
|
|
Hello
Pf course I'll assume you are doing this using COM interop. Actually the dll that's in your application's folder is something like a router. All it does is to call whatever version of Excel that's present on the user's computer to do the job.
So it all depends on the version that's installed on the runtime machine. To solve the issue you have two options:
1- In the reference list of your project try to set ht eIsolated property of the interop library to true -this tries to prevent version conflect, but sometimes doesn't work-
2- Make Excel 2000 as a "minimum requirement" for your application, so that users would know that have to have it on their machines.
3- Remove whatever features you are using that requires Excel 2000 to be on the machine -This is NOT guranteed to solve the issue. Actually it's likely NOT to work!-
4- You can also try 3rd party libraries which doesn't require Excel to be installed at all.
And for the solution suggested by Ista,it would work, but it's hard to implement specially with large applications such as Excel, as each dll may call other functions in other dlls.
Regards
|
|
|
|
|
Hi to all,
I want to perform DirectShow coding in VC# 2005. In that I want to set properties of 'Mpeg-2 Demultiplexer' Filter.
Regarding that I have code written in C++ as follows,
BYTE SeqHdr[] = { ... };
<br />
AM_MEDIA_TYPE mt;<br />
ZeroMemory(&mt, sizeof(AM_MEDIA_TYPE));<br />
mt.majortype = MEDIATYPE_Video ;<br />
mt.subtype = MEDIASUBTYPE_MPEG2_VIDEO;<br />
mt.formattype = FORMAT_MPEG2Video;<br />
<br />
mt.cbFormat = sizeof(MPEG2VIDEOINFO) + sizeof(SeqHdr);<br />
mt.pbFormat = (BYTE*)CoTaskMemAlloc(mt.cbFormat);<br />
if (mt.pbFormat == NULL)<br />
{<br />
}<br />
ZeroMemory(mt.pbFormat, mt.cbFormat);<br />
<br />
MPEG2VIDEOINFO *pMVIH = (MPEG2VIDEOINFO*)mt.pbFormat
This code is obtained from http://windowssdk.msdn.microsoft.com/en-us/library/ms787857.aspx[^]
How to Convert it into C#? What is the interface for 'MPEG2VIDEOINFO' in C#?
Thanks & Best Regards,
Aniket
|
|
|
|
|
Search for the DirectShow.NET lib on SourceForge. Then once you have it figured out, write an article
|
|
|
|
|
leppie wrote: Search for the DirectShow.NET lib on SourceForge.
I have DirectShow.NET lib. And I have designed a filter graph using it in C#. But when I tried to set properties of 'Mpeg-2 Demultiplexer' Filter using IMpeg2Demultiplexer Interface in C#. This I have done in VC++, for following properties I failed to convert in into C#.
memset(&Video_Info , 0x0 , sizeof(MPEG2VIDEOINFO));
#if !USE_DUMP_EX_FILTER
pMediaVideoType.cbFormat = sizeof(MPEG2VIDEOINFO);
#endif
#if !USE_DUMP_EX_FILTER
pMediaVideoType.pbFormat = (BYTE *)&Video_Info;
#endif
( pMediaVideoType is of 'AMMediaType' DataType). I didn't found Interface 'MPEG2VIDEOINFO' in C#. What should be done to set this properties?
Plz, help me.
Regards,
Aniket
|
|
|
|
|
Is there any way that i can receive any arguments from any Audio or media files or vice versa? ex: mp3 !!!
please help me !!!!
|
|
|
|
|
Tell it you don't like its mother - That'll usually start an argument.
|
|
|
|