stack.aljunic.com

Simple .NET/ASP.NET PDF document editor web control SDK

Often you will need to raise additional events from objects that follow the BackgroundWorker design pattern. For example, let s say you want to augment IterativeBackgroundWorker to raise an event when the worker starts its work and for this event to pass the exact time that the worker thread started as an event argument. Listing 13-3 shows the extra code you need to add to the IterativeBackgroundWorker type to make this happen. We use this extra code in the next section. Listing 13-3. Code to Raise GUI-Thread Events from an IterativeBackgroundWorker Object open System open System.Threading type IterativeBackgroundWorker<'a>(...) = let worker = ... // The constructor captures the synchronization context. This allows us to post // messages back to the GUI thread where the BackgroundWorker was created. let syncContext = SynchronizationContext.Current do if syncContext = null then failwith "no synchronization context found" let triggerStarted,started = IEvent.create()

ssrs code 128, ssrs code 39, ssrs fixed data matrix, winforms pdf 417 reader, winforms qr code reader, winforms upc-a reader, itextsharp remove text from pdf c#, c# replace text in pdf, winforms ean 13 reader, itextsharp remove text from pdf c#,

The columns in this table we ll be using for the metrics represent: NAME: the name of the statistic we are gathering (PGA and UGA information from V$SESSTAT for the current session, plus all of the memory information for the database instance as well as temporary tablespace writes). VALUE: the value of the given metric. ACTIVE: the number of other sessions doing work in the database. Before we start, we assume an idle database; we are the only user session right now, hence the value of zero.

I then ran the following SQL*Plus script in an interactive session. The table T had been created beforehand (above) with about 70,000 rows in it. connect / set echo on declare l_first_time boolean default true; begin for x in ( select * from t order by 1, 2, 3, 4 ) loop if ( l_first_time ) then insert into sess_stats ( name, value, active ) select name, value, (select count(*) from v$session where status = 'ACTIVE' and username is not null) from ( select a.name, b.value from v$statname a, v$sesstat b where a.statistic# = b.statistic# and b.sid = (select sid from v$mystat where rownum=1) and (a.name like '%ga %' or a.name like '%direct temp%') union all select 'total: ' || a.name, sum(b.value) from v$statname a, v$sesstat b, v$session c where a.statistic# = b.statistic# and (a.name like '%ga %' or a.name like '%direct temp%') and b.sid = c.sid and c.username is not null group by 'total: ' || a.name ); l_first_time := false; end if; end loop; end; / commit; This script sorts the big table T using PGA automatic memory management. Then, for that session, it captures all of the PGA/UGA memory settings as well as sort-to-disk activity. In addition, the UNION ALL adds system-level metrics about the same (total PGA memory, total UGA memory and so on). I ran that script against a database started with the following initialization settings: *.compatible='11.2.0.0.0' *.control_files='/home/ora11gr2/app/ora11gr2/oradata/orcl/control01.ctl','/home/ora11gr2/app /ora11gr2/flash_recovery_area/orcl/control02.ctl' *.db_block_size=8192 *.db_name='orcl'

// Raise the event when the worker starts. This is done by posting a message // to the captured synchronization context. do worker.DoWork.Add(fun args -> syncContext.Post(SendOrPostCallback(fun _ -> triggerStarted(DateTime.Now)), state=null) ... /// The Started event gets raised when the worker starts. It is /// raised on the GUI thread (i.e. in the synchronization context of /// the thread where the worker object was created). // It has type IEvent<DateTime> member x.Started = started The simple way to raise additional events is often wrong. For example, it is tempting to simply create an event, arrange for it to be triggered, and publish it, as you would do for a GUI control. However, if you do that, you will end up triggering the event on the background worker thread, and its event handlers will run on that thread. This is dangerous, because most GUI objects (and many other objects) can be accessed only from the thread they were created on; this is a restriction enforced by most GUI systems. One of the nice features of the BackgroundWorker class is that it automatically arranges to raise the RunWorkerCompleted and ProgressChanged events on the GUI thread. We have shown how to achieve this in Listing 13-3. Technically speaking, the extended IterativeBackgroundWorker object has captured the synchronization context of the thread where it was created and posts an operation back to that synchronization context. A synchronization context is just an object that lets you post operations back to another thread. For threads such as a GUI thread, this means posting an operation will post a message through the GUI event loop.

   Copyright 2020.