From: Michael Dichtl Date: 2007-07-04T17:13:56+09:00 Subject: WIN32OLE_EVENT causes cpu running 100% Hello! I have some code do catch some events from MS Outlook. Especially TastItem events. But my problem is, when catching the events, the CPU is running at 100%. Is there any chance to do it in an other way? My code is here: ******************************************* class OutlookEvents include Singleton OL_FOLDER_TASKS = 13 OL_TASK_NOT_STARTET = 0 OL_TASK_IN_PROGRESS = 1 OL_TASK_COMPLETE = 2 OL_TASK_WAITING = 3 OL_TASK_DEFERRED = 4 def initialize() begin @ol = WIN32OLE.connect("Outlook.Application") rescue @ol = WIN32OLE.new("Outlook.Application") end end def default_handler(event, *args) puts event puts args end def handle_task_events() appNS = @ol.Application.GetNamespace("MAPI") appTasks = appNS.GetDefaultFolder(OL_FOLDER_TASKS) appItems = appTasks.Items appEvents = WIN32OLE_EVENT.new(@ol, "ApplicationEvents") appItems.each do |item| if(item.Status != OL_TASK_DEFERRED) && (item.Status != OL_TASK_COMPLETE) events = WIN32OLE_EVENT.new(item, "ItemEvents") #event = events.on_event() do |*args| event = events.on_event("Open") do |*args| puts " ... got item events!" sleep 0.5 default_handler(event, *args) #sleep 3 # stop_listening = true end end end stop_listening = false appEvent = appEvents.on_event("Quit") do |*args| puts " ... got application events!" sleep 0.5 default_handler(appEvent, *args) stop_listening = true end WIN32OLE_EVENT.message_loop until stop_listening End outlook = OutlookEvents.instance outlook.handle_task_events() *******************************************************************+ Thnx, Michael