Synchronous events - DAQmxRegisterEveryNSamplesEvent
Hello,
I am writing a data acquisition application using an 18-bit PCI-6281 A/D board, on Windows XP using Borland C++ Builder 6.
The documentation for DAQmxRegisterEveryNSamplesEvent says that if the DAQmx_Val_SynchronousEventCallbacks flag is used, then the event callbacks will occur in the thread that registered the event, if messages are being processed. The "message processing" mention in the documentation seems rather vague to me, since it doesn't describe which Windows messages should be processed. So far I have been unable to find any further documentation or code examples that show how to use synchronous events.
My question is, how can I set up the "message processing" to use synchronous events? Any help would be appreciated.
Thanks very much,
Markus Svilans.
Please ignore this message, I accidentally posted it in the wrong section. (So much for getting it right the first time
Regards,
Markus.
Similar Messages
-
In my deployment I have 2 brokers, and 3 session hosts. I finally installed Update 1 and all following updates available (the ones that were available about two weeks before). Also updated Forefront to v4.3 (SCCM managed).
I have roaming TS profiles enabled with folder redirection and also policy set to "delete local copy of roaming profiles" after logout. Profile folders are on a network share (Server 2003). Things were working ok until Update 1 and rest of updates
got installed.
I started getting events 1509 and 1504 when users logoff and the screen displays "Your roaming profile was not completely synchronized" message briefly. The only file affected so far is ntuser.pol.
There are two variations of the event, one claiming it cannot write the local server copy to fileshare, and the opposite, from file share to c:\users\username.
====
Windows cannot copy file \\server\profileshare\username.V2\ntuser.pol to location C:\Users\username\ntuser.pol. This error may be caused by network problems or insufficient security rights.
DETAIL - Access is denied.
=====
Windows cannot copy file C:\Users\username\ntuser.pol to location \\server\profileshare\username.V2\ntuser.pol. This error may be caused by network problems or insufficient security rights.
DETAIL - Cannot create a file when that file already exists.
==========
Permissions have not changed. The only thing changing is the Updates installed on the servers. I tried running with AV realtime protection off, no change. Ntuser.pol is already on the exclude list in Forefront.
This is happening on my test server and 2 prd servers. Any ideas. I looked for related hotfixes but not coming up with anything.
The whole reason for installing Update 1 was so that we can continue to receive security updates...Hi,
Thanks for your comment.
When a roaming profile user logs off, the NTuser.dat file is always updated on the roaming profile share. The corresponding NTuser.pol file is only updated if the timestamp of the local copy that was created at logon is newer than the copy found in the roaming
profile share. A synchronization problem may occur if a user with a roaming profile logs on to multiple client computers at the same time. This can eventually cause policy settings to be applied incorrectly.
For example, if the Group Policy loopback feature is applied on one of the client computers, the NTuser.dat file on the roaming profile share may contain loopback policy settings that are not present in the NTuser.pol file. If this problem occurs, the loopback
policy settings that are targeted at one client computer may be unexpectedly applied to a user who logs on to a different client computer.
So please check the permission or group policy which you have applied and also whether you are performing multiple connection at a time.
Note: This KBhere providing only for reference as it’s for previous version.
Hope it helps!
Thanks.
Dharmesh Solanki
TechNet Community Support -
Try/catching errors occuring in synchronous event handlers
Hi,
I know that using try/catch in flash player it is possible to catch only synchronous errors, but recently I ran into code in our application which I strongly believe is synchronous but it behaves as if it wasn't.
In example below I create event listener and inside try/catch I dispatch event. Handler function throws error. Executing code stops when error is thrown, so message "after throwing error" won't be logged, but try/catch block catches nothing and code executes as if nothing happened after event dispatch.
Dispatching event on element executes handler method immediately so it is synchronous execution. Event call stack which is displayed in debug versions of flash player, shows every function from creation of class to execution of handler.
Generally flash applications relays heavily on events and in my case it caused ours users projects to be irreversibly corrupted, because of this continuing to work after error, which I even can't properly detect and handle, cause it's going throught 5 or more event handlers and adding try/catch to each handler would create enormous chaos in my code. So my question is why does flash player behaves like this? Are there any ways to tell compiled SWF file to treat such cases as synchronous calls, f.e. compilation parameters?
package
import flash.display.Sprite;
import flash.events.Event;
import flash.events.EventDispatcher;
import flash.text.TextField;
public class TestApp extends Sprite
public var cTextField:TextField;
public function TestApp()
cTextField = new TextField();
cTextField.width = 300;
cTextField.height = 200;
addChild(cTextField);
onAppCreated();
protected function onAppCreated():void
var eventName:String = "my_event";
var caughtError:Boolean = false;
var dispatcher:EventDispatcher = new EventDispatcher();
dispatcher.addEventListener(eventName, handler);
try
dispatcher.dispatchEvent(new Event(eventName));
} catch (error:Error)
caughtError = true;
cTextField.text += caughtError ? "caught error\n" : "error wasn't caught\n";
protected function handler(event:Event):void
cTextField.text += "before throwing error\n";
throw new Error("throw error");
cTextField.text += "after throwing error\n";Okay, nobody bit. Sorry.
The only way to really figure out what is going on is to look at a running example with a C++ debugger. I'm particularly curious about whether this problem happens in a specific browser/os combination (we may be working around a quirk of that platform), or if it's something that happens everywhere.
The most effective way to proceed is going to be to file a bug with a simplified, executable example (source and compiled SWF, ideally) that demonstrates the problem. This will help me route the bug to a developer and get you an answer in the shortest time possible.
You can file a bug here:
http://bugbase.adobe.com/
If you reply here with the bug number, I'll get it assigned to an engineer.
Thanks! -
Synchronizing events on iCal server
Hello!
Has a customized OS X Lion Server installed with a valid SSL class 2certificate.
On a server configured to iCal.
There is a problem with the work of iCal on iPhones:
- Added by either of two user events, or do not appear on the iPhone, orappear only after you open iCal on your phone
the phone settings "Loading Data" Push and every 15 minutes
OS on MacBook OS X Lion, the iPhone last firmware
Please tell me how to get on the phone to update itself without user action
thanks in advanceMaybe someone in the Lion Server Forum would be able to help?
Regards,
Colin R. -
Hi,
In my program I want that an event occurs every 10 seconds. I think I need a timer and a method where I go into when the timer is at multiples of 10. Can you help me?class YourTimerTask extends TimerTask {
public void run() {
// do whatever has to be done
Timer timer = new Timer();
timer.scheduleAtFixedRate(new YourTimerTask(), 10000, 10000); // every 10 seconds, starting in 10 seconds -
Data Read event in DAQmx with VB6
Hi,
I'm new to NI-DAQmx, I'll develop DAQ applications with VB.Net and DAQmx but feel maybe it's better to try with VB6 first. I've looked at the examples for DAQmx 7.5 using VB6, but have not been able to find an equivalent event to the CWAI_AcquiredData(,) event for the activeX controls in traditional NI-DAQ. My applications will continuously acquire analog data and should parse data in such an event if there is one.
Look forward to your advice.
Thank you in advance,
LogicTHello LogicT
Microsoft provides a free book that will guide users who are upgrading
to VB.NET. It's pretty comprehensive and can be downloaded for offline
reading. See this link for more information. Get 'em while they're hot
For the VB 6.0 type library appraoch, you could use the DAQmxRegisterEveryNSamplesEvent function to register
for a synchronous event to inform you when a certain number of samples
have been acquired. You could then call the read function inside of
this event. Or you could just call the read in a loop with
Application.DoEvents. But this latter approach might cause UI
delays,especially if your sampling rate is slow and it takes a while to
acquire the data.
But honestly, if the ultimate goal is to move to VB.NET, then I would
not recommend the approach you're taking. The DAQmx API for .NET is a
native .NET library. The documentation for it is integrated into the
Visual Studio Help system. There are alot more shipping examples and
concept documents for the .NET library then there are for the VB 6.0
type library for DAQmx. Trying to make a direct conversion from the VB
6.0 type library application to a VB.NET app will not provide you with
optimal results. If the end goal is to have a VB.NET DAQmx
application, I would recommend starting in VB.NET. Use the book I
mentioned above as a starting resource. The example you're looking for
is under ..\DotNET\Examples\DAQmx\Analog In\Measure
Voltage\ContAcqVoltageSamples_IntClk
PS: Even thought the path mentioned by E.Lee has Measurement Studio in
there, you do not need to purchase Measurement Studio to get the .NET
DAQmx API. It is available as part of the DAQmx driver for free. The
Help and examples are all included.
I hope this helps
Bilal Durrani
NI -
Sharepoint 2013 ItemAdded event receiver for renaming files is not working
In SP 2013 I coded an event receiver that intercepts the ItemAdded event and it just renames the file.
It is a synchronous event (I added <Synchronization>Synchronous</Synchronization> in the Elements.xml).
This is the code:
public override void ItemAdded(SPItemEventProperties properties)
SPSecurity.RunWithElevatedPrivileges(delegate()
try
OutputDebugStringA("Inside ItemAdded");
string szHttpUrl = properties.WebUrl + "/" + properties.AfterUrl;
SPWeb openedWeb = properties.Web.Site.OpenWeb(properties.Web.ID);
SPFile spf = openedWeb.GetFile(szHttpUrl);
EventFiringEnabled = false;
string szUrl = properties.AfterUrl;
szUrl = szUrl + ".renamed";
string szNewFileName;
if (szUrl.LastIndexOf('\\') != -1) szNewFileName = szUrl.Substring(szUrl.LastIndexOf('\\') + 1);
else if (szUrl.LastIndexOf('/') != -1) szNewFileName = szUrl.Substring(szUrl.LastIndexOf('/') + 1);
else szNewFileName = szUrl;
if (properties.ListItem != null)
properties.ListItem["Title"] = szNewFileName;
properties.ListItem.Update();
spf.MoveTo(szUrl);
EventFiringEnabled = true;
base.ItemAdded(properties);
OutputDebugStringA("Renaming to " + szUrl);
catch (System.Exception exception)
OutputDebugStringA("ItemAdded ERROR: " + exception.ToString());
The problem is that when I upload a .txt file using Internet Explorer, just after the renaming is done, IE says that something went wrong and when I inspect the log files I see:
SPRequest.GetFileAndFolderProperties: UserPrincipalName=i:0).w|s-1-5-21-4050800873-4278272723-3073177257-500, AppPrincipalName= ,bstrUrl=http://sp2013/sites/demo/subsite1 ,bstrStartUrl=Shared Documents/test2.txt ,ListDocsFlags=16400 ,bThrowException=True 0fa7689c-674b-5045-c3a2-b214a5d4cbed
01/09/2014 15:29:26.75 w3wp.exe (0x1544) 0x16F4 SharePoint Foundation
General ai1wu Medium System.IO.FileNotFoundException: <nativehr>0x80070002</nativehr><nativestack></nativestack>,
StackTrace: at Microsoft.SharePoint.SPWeb.GetFileOrFolderProperties(String strUrl, ListDocsFlags listDocsFlags, Boolean throwException, SPBasePermissions& permMask) at Microsoft.SharePoint.SPFile.PropertiesCore(Boolean
throwException) at Microsoft.SharePoint.SPFile.get_Length() at Microsoft.Office.RecordsManagement.PolicyFeatures.ApplicationPages.UploadPage.OnSubmit(Object o, EventArgs e) at Microsoft.Office.RecordsManagement.PolicyFeatures.ApplicationPages.UploadExPage.OnSubmit(Object
o, EventArgs e) at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) at System.Web.UI.Page.ProcessRequest(Boolean includeSta... 0fa7689c-674b-5045-c3a2-b214a5d4cbed
...gesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) at System.Web.UI.Page.ProcessRequest() at System.Web.UI.Page.ProcessRequest(HttpContext context) at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) at System.Web.HttpApplication.PipelineStepManager.ResumeSteps(Exception error) at System.Web.HttpApplication.BeginProcessRequestNotification(HttpContext
context, AsyncCallback cb) at System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) at System.Web.Hosting.PipelineRuntime.ProcessRequestNotificationHelper(IntPtr
rootedObjectsPointer, IntPtr nativeRequestContex... 0fa7689c-674b-5045-c3a2-b214a5d4cbed
...t, IntPtr moduleData, Int32 flags) at System.Web.Hosting.PipelineRuntime.ProcessRequestNotification(IntPtr rootedObjectsPointer, IntPtr nativeRequestContext, IntPtr moduleData, Int32 flags) at System.Web.Hosting.UnsafeIISMethods.MgdIndicateCompletion(IntPtr
pHandler, RequestNotificationStatus& notificationStatus) at System.Web.Hosting.UnsafeIISMethods.MgdIndicateCompletion(IntPtr pHandler, RequestNotificationStatus& notificationStatus) at System.Web.Hosting.PipelineRuntime.ProcessRequestNotificationHelper(IntPtr
rootedObjectsPointer, IntPtr nativeRequestContext, IntPtr moduleData, Int32 flags) at System.Web.Hosting.PipelineRuntime.ProcessRequestNotification(IntPtr rootedObjectsPointer, IntPtr nativeRequestContext, IntPtr moduleData, Int32 flags)
0fa7689c-674b-5045-c3a2-b214a5d4cbed
So it is clear that the fact that I renamed the file is causing an issue in the SharePoint upload logic.
As a solution what I did was to not declare it as Synchronous, but if I do it then there is another error when Sharepoint shows the Edit Properties dialog... in this case the upload is OK but when it is time to show that Edit Property dialog IE fails and
says that the file has been already modified, or that "something went wrong".
If I use a synchronous event I get one problem. If I use the asynchronous event I get another problem... It's very frustating and I am pretty sure that a so important API like Event Receivers should have support renaming files so I hope someone can tell
me what I am doing wrong.
Thanks in advanceMay be you want to consider using the following code and see if it works for you.
http://social.msdn.microsoft.com/Forums/sharepoint/en-US/40c78e03-2dca-4083-89d2-a7430099da68/how-do-i-change-the-name-property-of-a-file-in-a-document-library?forum=sharepointdevelopment
Amit -
What is Triggering and Handling Events in ABAP OOPs
Gowri
) TYPE type ..
To declare static events, use the following statement:
CLASS-EVENTS ... ...
It links a list of handler methods with corresponding trigger methods. There are four different types of event.
It can be
· An instance event declared in a class
· An instance event declared in an interface
· A static event declared in a class
· A static event declared in an interface
The syntax and effect of the SET HANDLER depends on which of the four cases listed above applies.
For an instance event, you must use the FOR addition to specify the instance for which you want to register the handler. You can either specify a single instance as the trigger, using a reference variable
After the RAISE EVENT statement, all registered handler methods are executed before the next statement is processed (synchronous event handling). If a handler method itself triggers events, its handler methods are executed before the original handler method continues. To avoid the possibility of endless recursion, events may currently only be nested 64 deep.
Handler methods are executed in the order in which they were registered. Since event handlers are registered dynamically, you should not assume that they will be processed in a particular order. Instead, you should program as though all event handlers will be executed simultaneously.
"Example :
REPORT demo_class_counter_event.
CLASS counter DEFINITION.
PUBLIC SECTION.
METHODS increment_counter.
EVENTS critical_value EXPORTING value(excess) TYPE i.
PRIVATE SECTION.
DATA: count TYPE i,
threshold TYPE i VALUE 10.
ENDCLASS.
CLASS counter IMPLEMENTATION.
METHOD increment_counter.
DATA diff TYPE i.
ADD 1 TO count.
IF count > threshold.
diff = count - threshold.
RAISE EVENT critical_value EXPORTING excess = diff.
ENDIF.
ENDMETHOD.
ENDCLASS.
CLASS handler DEFINITION.
PUBLIC SECTION.
METHODS handle_excess
FOR EVENT critical_value OF counter
IMPORTING excess.
ENDCLASS.
CLASS handler IMPLEMENTATION.
METHOD handle_excess.
WRITE: / 'Excess is', excess.
ENDMETHOD.
ENDCLASS.
DATA: r1 TYPE REF TO counter,
h1 TYPE REF TO handler.
START-OF-SELECTION.
CREATE OBJECT: r1, h1.
SET HANDLER h1->handle_excess FOR ALL INSTANCES.
DO 20 TIMES.
CALL METHOD r1->increment_counter.
ENDDO.
The class COUNTER implements a counter. It triggers the event CRITICAL_VALUE when a threshold value is exceeded, and displays the difference. HANDLER can handle the exception in COUNTER. At runtime, the handler is registered for all reference variables that point to the object.
Reward points if it is usefull ...
Girish -
Hi all,
I want to know the significance of creating event handler method in Class builder.
and how it can be used at the time of event trigger.( Is it called automatically or programmer need to call it explicitly in the program.)
Thanks,
Sushant singhHi Sushant,
1. In ABAP Objects, triggering and handling an event means that certain methods act as triggers and trigger events, to which other methods - the handlers - react. This means that the handler methods are executed when the event occurs.
2.To trigger an event, a class must
Declare the event in its declaration part
Trigger the event in one of its methods
3.You declare events in the declaration part of a class or in an interface. To declare instance events, use the following statement:
EVENTS evt EXPORTING... VALUE(e1 e2 ...) TYPE type [OPTIONAL]..
4. An instance event in a class can be triggered by any instance method in the class. Static events can be triggered by any method. However, static methods can only trigger static events. To trigger an event in a method, use the following statement:
RAISE EVENT evt EXPORTING e1 = f1 e2 = f2 ...
5. Events are handled using special methods. To handle an event, a method must
be defined as an event handler method for that event
be registered at runtime for the event.
Declaring Event Handler Methods
Any class can contain event handler methods for events from other classes. You can, of course, also define event handler methods in the same class as the event itself. To declare an event handler method, use the following statement:
METHODS meth FOR EVENT evt OF cif IMPORTING e1 e2 ...
6. Registering Event Handler Methods
To allow an event handler method to react to an event, you must determine at runtime the trigger to which it is to react. You can do this with the following statement:
SET HANDLER h1 h2 ... [FOR]...
It links a list of handler methods with corresponding trigger methods. There are four different types of event.
7. Timing of Event Handling
After the RAISE EVENTstatement, all registered handler methods are executed before the next statement is processed (synchronous event handling). If a handler method itself triggers events, its handler methods are executed before the original handler method continues. To avoid the possibility of endless recursion, events may currently only be nested 64 deep.
Handler methods are executed in the order in which they were registered. Since event handlers are registered dynamically, you should not assume that they will be processed in a particular order. Instead, you should program as though all event handlers will be executed simultaneously.
Reward if useful. -
cud u plz guide me how to create the events in oops abap .
why we r using methods instead of perform statements in oops abap?Hi,
Triggering and Handling Events
In ABAP Objects, triggering and handling an event means that certain methods act as triggers and trigger events, to which other methods - the handlers - react. This means that the handler methods are executed when the event occurs.
This section contains explains how to work with events in ABAP Objects. For precise details of the relevant ABAP statements, refer to the corresponding keyword documentation in the ABAP Editor.
Triggering Events
To trigger an event, a class must
· Declare the event in its declaration part
· Trigger the event in one of its methods
Declaring Events
You declare events in the declaration part of a class or in an interface. To declare instance events, use the following statement:
EVENTS ) TYPE type ..
To declare static events, use the following statement:
CLASS-EVENTS ... ...
It links a list of handler methods with corresponding trigger methods. There are four different types of event.
It can be
· An instance event declared in a class
· An instance event declared in an interface
· A static event declared in a class
· A static event declared in an interface
The syntax and effect of the SET HANDLER depends on which of the four cases listed above applies.
For an instance event, you must use the FOR addition to specify the instance for which you want to register the handler. You can either specify a single instance as the trigger, using a reference variable ...
The registration applies automatically to the whole class, or to all of the classes that implement the interface containing the static event. In the case of interfaces, the registration also applies to classes that are not loaded until after the handler has been registered.
Timing of Event Handling
After the RAISE EVENT statement, all registered handler methods are executed before the next statement is processed (synchronous event handling). If a handler method itself triggers events, its handler methods are executed before the original handler method continues. To avoid the possibility of endless recursion, events may currently only be nested 64 deep.
Handler methods are executed in the order in which they were registered. Since event handlers are registered dynamically, you should not assume that they will be processed in a particular order. Instead, you should program as though all event handlers will be executed simultaneously.
"Example :
REPORT demo_class_counter_event.
CLASS counter DEFINITION.
PUBLIC SECTION.
METHODS increment_counter.
EVENTS critical_value EXPORTING value(excess) TYPE i.
PRIVATE SECTION.
DATA: count TYPE i,
threshold TYPE i VALUE 10.
ENDCLASS.
CLASS counter IMPLEMENTATION.
METHOD increment_counter.
DATA diff TYPE i.
ADD 1 TO count.
IF count > threshold.
diff = count - threshold.
RAISE EVENT critical_value EXPORTING excess = diff.
ENDIF.
ENDMETHOD.
ENDCLASS.
CLASS handler DEFINITION.
PUBLIC SECTION.
METHODS handle_excess
FOR EVENT critical_value OF counter
IMPORTING excess.
ENDCLASS.
CLASS handler IMPLEMENTATION.
METHOD handle_excess.
WRITE: / 'Excess is', excess.
ENDMETHOD.
ENDCLASS.
DATA: r1 TYPE REF TO counter,
h1 TYPE REF TO handler.
START-OF-SELECTION.
CREATE OBJECT: r1, h1.
SET HANDLER h1->handle_excess FOR ALL INSTANCES.
DO 20 TIMES.
CALL METHOD r1->increment_counter.
ENDDO.
The class COUNTER implements a counter. It triggers the event CRITICAL_VALUE when a threshold value is exceeded, and displays the difference. HANDLER can handle the exception in COUNTER. At runtime, the handler is registered for all reference variables that point to the object.
Regards,
Omkar. -
C# COM server events "lost" when raising events while Excel is in edit mode
I posted this question on StackOverflow (http://stackoverflow.com/questions/23798443/c-sharp-com-server-events-lost-when-raising-events-while-excel-is-in-edit-mode) but did not receive a good answer, so I'm trying my luck here.
I have an in-proc COM server written in C# (using .NET Framework 3.5) that raises COM events based on this example: http://msdn.microsoft.com/en-us/library/dd8bf0x3(v=vs.90).aspx
Excel VBA is the most common client of my COM server. I’ve found that when I raise COM events while Excel is in edit mode (e.g. a cell is being edited) the event is “lost”. Meaning, the VBA event handler is never called (even after the Excel
edit mode is finished) and the call to the C# event delegate passes through and fails silently with no exceptions being thrown. Do you know how I can detect this situation on my COM server? Or better still, make the event delegate call block until
Excel is out of edit mode?
I have tried:
Inspecting the properties of the event delegate – could not find any property to indicate that the event failed to be raised on the client.
Calling the event delegate directly from a worker thread and from the main thread – event not raised on the client, no exceptions thrown on the server.
Pushing the event delegate onto a worker thread’s Dispatcher and invoking it synchronously – event not raised on the client, no exceptions thrown on the server.
Pushing the event delegate onto the main thread’s Dispatcher and invoking it synchronously and asynchronously – event not raised on the client, no exceptions thrown on the server.
Checking the status code of the Dispatcher.BeginInvoke call (using DispatcherOperation.Status) – the status is always ends with “Completed”, and is never in “Aborted” state.
Creating an out-of-proc C# COM server exe and tested raising the events from there – same result, event handler never called, no exceptions.
Since I get no indication that the event was not raised on the client, I cannot handle this situation in my code.
I have tested this with Excel 2010 and Excel 2013.
Here is a simple test case. The C# COM server:
namespace ComServerTest
public delegate void EventOneDelegate();
// Interface
[Guid("2B2C1A74-248D-48B0-ACB0-3EE94223BDD3"), Description("ManagerClass interface")]
[InterfaceType(ComInterfaceType.InterfaceIsDual)]
[ComVisible(true)]
public interface IManagerClass
[DispId(1), Description("Describes MethodAAA")]
String MethodAAA(String strValue);
[DispId(2), Description("Start thread work")]
String StartThreadWork(String strIn);
[DispId(3), Description("Stop thread work")]
String StopThreadWork(String strIn);
[Guid("596AEB63-33C1-4CFD-8C9F-5BEF17D4C7AC"), Description("Manager events interface")]
[InterfaceType(ComInterfaceType.InterfaceIsIDispatch)]
[ComVisible(true)]
public interface ManagerEvents
[DispId(1), Description("Event one")]
void EventOne();
[Guid("4D0A42CB-A950-4422-A8F0-3A714EBA3EC7"), Description("ManagerClass implementation")]
[ComVisible(true), ClassInterface(ClassInterfaceType.None)]
[ComSourceInterfaces(typeof(ManagerEvents))]
public class ManagerClass : IManagerClass
private event EventOneDelegate EventOne;
private System.Threading.Thread m_workerThread;
private bool m_doWork;
private System.Windows.Threading.Dispatcher MainThreadDispatcher = null;
public ManagerClass()
// Assumes this is created on the main thread
MainThreadDispatcher = System.Windows.Threading.Dispatcher.CurrentDispatcher;
m_doWork = false;
m_workerThread = new System.Threading.Thread(DoThreadWork);
// Simple thread that raises an event every few seconds
private void DoThreadWork()
DateTime dtStart = DateTime.Now;
TimeSpan fiveSecs = new TimeSpan(0, 0, 5);
while (m_doWork)
if ((DateTime.Now - dtStart) > fiveSecs)
System.Diagnostics.Debug.Print("Raising event...");
try
if (EventOne != null)
// Tried calling the event delegate directly
EventOne();
// Tried synchronously invoking the event delegate from the main thread's dispatcher
MainThreadDispatcher.Invoke(EventOne, new object[] { });
// Tried asynchronously invoking the event delegate from the main thread's dispatcher
System.Windows.Threading.DispatcherOperation dispOp = MainThreadDispatcher.BeginInvoke(EventOne, new object[] { });
// Tried synchronously invoking the event delegate from the worker thread's dispatcher.
// Asynchronously invoking the event delegate from the worker thread's dispatcher did not work regardless of whether Excel is in edit mode or not.
System.Windows.Threading.Dispatcher.CurrentDispatcher.Invoke(EventOne, new object[] { });
catch (System.Exception ex)
// No exceptions were thrown when attempting to raise the event when Excel is in edit mode
System.Diagnostics.Debug.Print(ex.ToString());
dtStart = DateTime.Now;
// Method should be called from the main thread
[ComVisible(true), Description("Implements MethodAAA")]
public String MethodAAA(String strValue)
if (EventOne != null)
try
// Tried calling the event delegate directly
EventOne();
// Tried asynchronously invoking the event delegate from the main thread's dispatcher
System.Windows.Threading.DispatcherOperation dispOp = System.Windows.Threading.Dispatcher.CurrentDispatcher.BeginInvoke(EventOne, new object[] { });
// Tried synchronously invoking the event delegate from the main thread's dispatcher
System.Windows.Threading.Dispatcher.CurrentDispatcher.Invoke(EventOne, new object[] { });
catch (System.Exception ex)
// No exceptions were thrown when attempting to raise the event when Excel is in edit mode
System.Diagnostics.Debug.Print(ex.ToString());
return "";
return "";
[ComVisible(true), Description("Start thread work")]
public String StartThreadWork(String strIn)
m_doWork = true;
m_workerThread.Start();
return "";
[ComVisible(true), Description("Stop thread work")]
public String StopThreadWork(String strIn)
m_doWork = false;
m_workerThread.Join();
return "";
I register it using regasm:
%SystemRoot%\Microsoft.NET\Framework\v2.0.50727\regasm /codebase ComServerTest.dll /tlb:ComServerTest.tlb
Excel VBA client code:
Public WithEvents managerObj As ComServerTest.ManagerClass
Public g_nCounter As Long
Sub TestEventsFromWorkerThread()
Set managerObj = New ComServerTest.ManagerClass
Dim dtStart As Date
dtStart = DateTime.Now
g_nCounter = 0
Debug.Print "Start"
' Starts the worker thread which will raise the EventOne event every few seconds
managerObj.StartThreadWork ""
Do While True
DoEvents
' Loop for 20 secs
If ((DateTime.Now - dtStart) * 24 * 60 * 60) > 20 Then
' Stops the worker thread
managerObj.StopThreadWork ""
Exit Do
End If
Loop
Debug.Print "Done"
End Sub
Sub TestEventFromMainThread()
Set managerObj = New ComServerTest.ManagerClass
Debug.Print "Start"
' This call will raise the EventOne event
managerObj.MethodAAA ""
Debug.Print "Done"
End Sub
' EventOne handler
Private Sub managerObj_EventOne()
Debug.Print "EventOne " & g_nCounter
g_nCounter = g_nCounter + 1
End Sub
This problem also occurs for a C++ MFC Automation server that raises COM events. If I raise the COM event from the main thread when Excel is in edit mode, the event handler is never called. No errors or exceptions are thrown on the server,
similar to my C# COM server. However, if I use the Global Interface Table to marshal the event sink interface from the main thread
back to the main thread, then invoking the event - it will block while Excel is in edit mode. (I also used COleMessageFilter to disable the busy dialog and not responding dialogs, otherwise I'd receive the exception:
RPC_E_CANTCALLOUT_INEXTERNALCALL It is illegal to call out while inside message filter.)
Knowing that, I tried to do the same on my C# COM server. I could instantiate the Global Interface Table (using the definition from pinvoke.net) and the message filter (using the IOleMessageFilter definition from MSDN). However, the event still
gets "lost" and does not block while Excel is in edit mode.
Here's my additional C# code to try to make use of the Global Interface Table:
namespace ComServerTest
// Global Interface Table definition from pinvoke.net
ComImport,
InterfaceType(ComInterfaceType.InterfaceIsIUnknown),
Guid("00000146-0000-0000-C000-000000000046")
interface IGlobalInterfaceTable
uint RegisterInterfaceInGlobal(
[MarshalAs(UnmanagedType.IUnknown)] object pUnk,
[In] ref Guid riid);
void RevokeInterfaceFromGlobal(uint dwCookie);
[return: MarshalAs(UnmanagedType.IUnknown)]
object GetInterfaceFromGlobal(uint dwCookie, [In] ref Guid riid);
ComImport,
Guid("00000323-0000-0000-C000-000000000046") // CLSID_StdGlobalInterfaceTable
class StdGlobalInterfaceTable /* : IGlobalInterfaceTable */
public class ManagerClass : IManagerClass
//...skipped code already mentioned in earlier sample above...
//...also skipped the message filter code for brevity...
private Guid IID_IDispatch = new Guid("00020400-0000-0000-C000-000000000046");
private IGlobalInterfaceTable m_GIT = null;
public ManagerClass()
//...skipped code already mentioned in earlier sample above...
m_GIT = (IGlobalInterfaceTable)new StdGlobalInterfaceTable();
public void FireEventOne()
// Using the GIT to marshal the (event?) interface from the main thread back to the main thread (like the MFC Automation server).
// Should we be marshalling the ManagerEvents interface pointer instead? How do we get at it?
uint uCookie = m_GIT.RegisterInterfaceInGlobal(this, ref IID_IDispatch);
ManagerClass mgr = (ManagerClass)m_GIT.GetInterfaceFromGlobal(uCookie, ref IID_IDispatch);
mgr.EventOne(); // when Excel is in edit mode, event handler is never called and does not block, event is "lost"
m_GIT.RevokeInterfaceFromGlobal(uCookie);
I’d like my C# COM server to behave in a similar way to the MFC Automation server. Is this possible? I think I should be registering the ManagerEvents interface pointer in the GIT but I don't know how to get at it? I tried using Marshal.GetComInterfaceForObject(this,
typeof(ManagerEvents)) but that just throws an exception: System.InvalidCastException: Specified cast is not valid.
Thanks.Hi Jason-F,
I’ve found that when I raise COM events while Excel is in edit mode (e.g. a cell is being edited) the event is “lost”. Meaning,
the VBA event handler is never called (even after the Excel edit mode is finished) and the call to the C# event delegate passes through and fails silently with no exceptions being thrown.
Do you mean you didn't raise EventOne event? EventOne handler like following?
' EventOne handler
Private Sub managerObj_EventOne()
Debug.Print "EventOne " & g_nCounter
g_nCounter = g_nCounter + 1
End Sub
After test your code, here is my screenshot
And here is my execute log in C# ComServerTest.
ManagerClass1/1/2015 5:48:11 PM
DoThreadWork()1/1/2015 5:48:12 PM
ManagerClass_EventOne()1/1/2015 5:48:17 PM
ManagerClass_EventOne()1/1/2015 5:48:22 PM
ManagerClass_EventOne()1/1/2015 5:48:27 PM
ManagerClass_EventOne()1/1/2015 5:48:32 PM
ManagerClass_EventOne()1/1/2015 5:48:37 PM
ManagerClass_EventOne()1/1/2015 5:48:42 PM
ManagerClass1/1/2015 5:49:56 PM
DoThreadWork()1/1/2015 5:49:56 PM
ManagerClass_EventOne()1/1/2015 5:50:01 PM
ManagerClass1/1/2015 5:50:04 PM
If i misunderstand you, please feel free to let me know.
Best regards,
kristin
We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click
HERE to participate the survey. -
How can I view all synchronized calendars online?
I have multiple calendars: my private google calendar, calendars from two institutes where I work and my iCal. Everything shows up well on my iPhone and my MacBook Pro.
My problem is that I want to be able to access all those on the go from my office PC online. When I log in to my iCal online, it only gives me my iCal events but none of the other synchronized events. How can I bring everything up when I am away from my MacBook?
Thanks!Can I upvote this? I was going to give up, and this little note solved my problem. the delegates thing. Wow, they bury that in the interface.
-
Multiple event receivers with a list
Hi All,
If there are two item event receivers attached with a list and event is cancelled by event receiver that trigger first, will second event receiver be invoked? As per my understanding that second event receiver will not be invoked.
I have a requirement where in case first event receiver cancel the event, second event recever should still be invoked.
do anyone has any idea aroound it?
Regards AmitHi, Amit KM.
http://msdn.microsoft.com/en-us/library/gg749858.aspx
Notice the following details:
Synchronous event receivers are called in sequential order based on the sequence number specified during event binding. This applies to both Before and After synchronous events.
Asynchronous After event receiver threads are initiated in sequential order based on the sequence number. However, there is no guarantee that they will finish in that same order.
An asynchronous After event can start at any time after its associated user action is performed. It may start before, at the same time as, or after the Web request is completed.
After a user initiates an action in the SharePoint user interface, and before SharePoint Foundation executes the user action, the synchronous Before events are raised. If there are multiple synchronous Before events, they are raised in the order specified
by their sequence number. Similarly, synchronous After events are raised after SharePoint Foundation executes the user action. These, too, are raised in the order specified by sequence number. As you can see, all synchronous events are processed in the same
thread as that in which the user action occurs.
Asynchronous After events, however, are processed on secondary threads.
So you're completely right that if the first event receiver has cancelled the operation, the second event receiver will never been executed.
In your case if you want second event receiver(B) to be invoked regardless of the first event receivers'
(A) result you can easily swap the sequence numbers for those event receivers.
Event Receiver Sequence
The event receiver sequence specifies the order in which an event receiver is executed in cases where an event triggers multiple event receivers. For example, if you have two
ItemAdded event receivers bound to the same list (one from Assembly "1" and the other from Assembly "2"), the event receiver that is bound with a lower sequence number is executed first. A practical example is adding an event receiver to a
system list that already has a system event receiver bound to it. In that case, you assign the new event receiver a higher sequence number.
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
<Receivers ListUrl="Lists/Tasks">
<Receiver>
<Assembly>MyReceiverAssembly, Version=1.0.0.0, Culture=Neutral,
PublicKeyToken=12e5e5525fb3d28a</Assembly>
<Class>MyReceiverAssembly.MyReceiverClass</Class>
<Type>ItemAdded</Type>
<Name>My ItemAdded Event Receiver</Name>
<Synchronization>Synchronous</Synchronization>
<SequenceNumber>1000</SequenceNumber>
</Receiver>
</Receivers>
</Elements>
LinkedIn Profile
SharePoint Advanced Visibility Options project
SharePoint Managed Metadata Claims Provider project -
Updating a custom field in ItemCheckingIn event of pages library of publishing portal.
I have Pages Library of publishing web. In this pages library I have a content type that has a few custom fields.
When ever a page is created and checked in in this library I want to send out an update email to users. The function that sends the email returns an Id to track the mails sent.
I want to store this id to the one of the custom fields of the content type attached to this pages library.
If I use item checkingIn event then list item is available but when i update it gives error probably due to the fact that in synchronous item the item is not yet created.
If i use CheckedIn event then it executes after the file is checked in , in that case it gives error asking me to check out the file first and the update the custom field.
Please suggest the best way to update a field in document library in synchronous event handlers or in asynchronous event handlers in the simplest of ways.
I do not want to check out the file in asynchronous event programatically for just one field and then re check it in.
Hi,
According to your post, my understanding is that you want to update list item in ItemCheckedIn method in Event Receiver.
The following code snippet for your reference:
/// <summary>
/// List Item Events
/// </summary>
public class EventReceiver1 : SPItemEventReceiver
/// <summary>
/// An item was checked in.
/// </summary>
public override void ItemCheckedIn(SPItemEventProperties properties)
SPListItem item = properties.ListItem;
item["Title"] = "Test1";
item.Update();
If the issue still exists, I suggest you debug your code or provide your code for further research.
http://sharepoint-kings.blogspot.com/2013/02/debugging-event-receivers-in-sharepoint.html
Thanks,
Dennis Guo
TechNet Community Support
Please remember to mark the replies as answers if they help and unmark them if they provide no help. If you have feedback for TechNet Subscriber Support, contact
[email protected]
Dennis Guo
TechNet Community Support -
Dear All,
Would you mind tell me the concept of the event in the ABAP objects.
Regards,
LukehI
Triggering and Handling Events
In ABAP Objects, triggering and handling an event means that certain methods act as triggers and trigger events, to which other methods - the handlers - react. This means that the handler methods are executed when the event occurs.
This section contains explains how to work with events in ABAP Objects. For precise details of the relevant ABAP statements, refer to the corresponding keyword documentation in the ABAP Editor.
Triggering Events
To trigger an event, a class must
· Declare the event in its declaration part
· Trigger the event in one of its methods
Declaring Events
You declare events in the declaration part of a class or in an interface. To declare instance events, use the following statement:
EVENTS ) TYPE type ..
To declare static events, use the following statement:
CLASS-EVENTS ... ...
It links a list of handler methods with corresponding trigger methods. There are four different types of event.
It can be
· An instance event declared in a class
· An instance event declared in an interface
· A static event declared in a class
· A static event declared in an interface
The syntax and effect of the SET HANDLER depends on which of the four cases listed above applies.
For an instance event, you must use the FOR addition to specify the instance for which you want to register the handler. You can either specify a single instance as the trigger, using a reference variable ...
The registration applies automatically to the whole class, or to all of the classes that implement the interface containing the static event. In the case of interfaces, the registration also applies to classes that are not loaded until after the handler has been registered.
Timing of Event Handling
After the RAISE EVENT statement, all registered handler methods are executed before the next statement is processed (synchronous event handling). If a handler method itself triggers events, its handler methods are executed before the original handler method continues. To avoid the possibility of endless recursion, events may currently only be nested 64 deep.
Handler methods are executed in the order in which they were registered. Since event handlers are registered dynamically, you should not assume that they will be processed in a particular order. Instead, you should program as though all event handlers will be executed simultaneously.
http://help.sap.com/saphelp_erp2004/helpdata/en/ce/b518b6513611d194a50000e8353423/frameset.htm
http://help.sap.com/saphelp_erp2004/helpdata/en/ce/b518b6513611d194a50000e8353423/frameset.htm
http://help.sap.com/saphelp_erp2004/helpdata/en/ce/b518b6513611d194a50000e8353423/frameset.htm
http://help.sap.com/saphelp_erp2004/helpdata/en/ce/b518b6513611d194a50000e8353423/frameset.htm
Maybe you are looking for
-
Is it possible to get the page count of a *.doc and * .xls document in java
Hi guys, How to determine the number of pages given a word document or an excel document.I searched many sites , found one in the forum about ImageDecoder it can determine the number of pages of tiff,jpeg etc images. but its not possible for *.do or
-
LaCie Ethernet Disk mini Home Edition
I'm considering buying a "LaCie Ethernet Disk mini Home Edition" http://www.lacie.com/us/products/product.htm?pid=10994 . The specs for this device says that it has iTunes Server support. Can I use this to stream content to my Apple TV without my com
-
I am having problems in viewing videos on facebook that friends have posted, I was able to do so upto and including yesterday any suggestions? As you can see I am not a computer tech just a granny trying to be!
-
ESC key not working in exe.
Hi, I'm using Captivate 5 and after publishing an exe project, when we view it, I cannot close the full screen published exe project via the ESC key. Nothing happens. I've heard of the Enter key closing out exe files, but not about the ESC key not wo
-
DVD does not recognize any movies
Hi everyone. I have just realized that I have a problem with my DVD drive. It will not play any movies. It does recognize and play CD's, DVD's with software and even Blank DVD's, but won't display the icon of a DVD with a movie on the desktop. I have