Pocket outlook - AppointmentsCollection class: ListChanged event

S

Sam

Hi guys,
I'm developing an application that get appointments from pocket outlook and
write them into registry keys. It can be useful when I use some rltoday
skin.
I tried with "Microsoft.WindowsMobile.PocketOutlook.OutlookSession" class.
I noticed that ListChanged event (in AppointmentCollection class) is rised
only when an appointment is added/deleted/modified/... programmatically.
Is there any way to "catch" an event (also using win ce API) when user
add/delete/modify an appointment using calendar application?
Thanks.
 
S

Sam

http://blog.opennetcf.com/ctacke/2008/10/20/TheCuttingRoomDetectingPOOMChanges.aspx
Thank you very much. It is very useful!!
It works with windows form but I'm not able to integrate it into my console application.
Please, I need help! Where I should put this code?
POOMHelper.OutlookItemChanged += new OutlookItemChangeDelegate(POOMHelper_OutlookItemChanged);

void POOMHelper_OutlookItemChanged(PIMNotificationMessage notification, PIMItemType itemType, int itemOID, int databaseOID)

{

switch (itemType)

{

case PIMItemType.Calendar:

{...}

break;}}


My Console application:

class Program
{
static Timer timer= new Timer();
static void Main(string[] args)
{
timer = new Timer();
timer.Interval = 500;
timer.OnTimerTick += timerTick;
Thread timerThread = timer.Start();
for (; ; )
Thread.Sleep(5000);
}

And:

class Timer
{
// Delegates
public delegate void Tick();

// Properties
public int Interval;
public Tick OnTimerTick;

// Private Data
Thread _timerThread;
volatile bool _bStop;

public void SleepIntermittently(int totalTime)
{
int sleptTime = 0;
int intermittentSleepIncrement = 10;

while (!_bStop && sleptTime < totalTime)
{
Thread.Sleep(intermittentSleepIncrement);
sleptTime += intermittentSleepIncrement;
}
}

public void Run()
{
while (!_bStop)
{
// Sleep for the timer interval
SleepIntermittently(Interval);
// Then fire the tick event
OnTimerTick();
}
}

public Thread Start()
{
_bStop = false;
_timerThread = new Thread(new ThreadStart(Run));
_timerThread.IsBackground = true;
_timerThread.Start();
return _timerThread;
}

public void Stop()
{
// Request the loop to stop
_bStop = true;
_timerThread.Join(1000);
_timerThread.Abort();
}
}
 
C

Chris Tacke, eMVP

IIRC, it works via Windows Messages, so you have to have a message pump to get the notifications. Sleep won't do it - you need to Get and Dispatch messages from the queue.


--

Chris Tacke, Embedded MVP
OpenNETCF Consulting
Giving back to the embedded community
http://community.OpenNETCF.com



Sam said:
Thank you very much. It is very useful!!
It works with windows form but I'm not able to integrate it into my console application.
Please, I need help! Where I should put this code?
POOMHelper.OutlookItemChanged += new OutlookItemChangeDelegate(POOMHelper_OutlookItemChanged);

void POOMHelper_OutlookItemChanged(PIMNotificationMessage notification, PIMItemType itemType, int itemOID, int databaseOID)

{

switch (itemType)

{

case PIMItemType.Calendar:

{...}

break;}}


My Console application:

class Program
{
static Timer timer= new Timer();
static void Main(string[] args)
{
timer = new Timer();
timer.Interval = 500;
timer.OnTimerTick += timerTick;
Thread timerThread = timer.Start();
for (; ; )
Thread.Sleep(5000);
}

And:

class Timer
{
// Delegates
public delegate void Tick();

// Properties
public int Interval;
public Tick OnTimerTick;

// Private Data
Thread _timerThread;
volatile bool _bStop;

public void SleepIntermittently(int totalTime)
{
int sleptTime = 0;
int intermittentSleepIncrement = 10;

while (!_bStop && sleptTime < totalTime)
{
Thread.Sleep(intermittentSleepIncrement);
sleptTime += intermittentSleepIncrement;
}
}

public void Run()
{
while (!_bStop)
{
// Sleep for the timer interval
SleepIntermittently(Interval);
// Then fire the tick event
OnTimerTick();
}
}

public Thread Start()
{
_bStop = false;
_timerThread = new Thread(new ThreadStart(Run));
_timerThread.IsBackground = true;
_timerThread.Start();
return _timerThread;
}

public void Stop()
{
// Request the loop to stop
_bStop = true;
_timerThread.Join(1000);
_timerThread.Abort();
}
}
 
S

Sam

I don't know much about what are you talking about...please can you give me any link?
Thanks..
"Chris Tacke, eMVP" <ctacke.at.opennetcf.dot.com> wrote in message IIRC, it works via Windows Messages, so you have to have a message pump to get the notifications. Sleep won't do it - you need to Get and Dispatch messages from the queue.


--

Chris Tacke, Embedded MVP
OpenNETCF Consulting
Giving back to the embedded community
http://community.OpenNETCF.com



Sam said:
Thank you very much. It is very useful!!
It works with windows form but I'm not able to integrate it into my console application.
Please, I need help! Where I should put this code?
POOMHelper.OutlookItemChanged += new OutlookItemChangeDelegate(POOMHelper_OutlookItemChanged);

void POOMHelper_OutlookItemChanged(PIMNotificationMessage notification, PIMItemType itemType, int itemOID, int databaseOID)

{

switch (itemType)

{

case PIMItemType.Calendar:

{...}

break;}}


My Console application:

class Program
{
static Timer timer= new Timer();
static void Main(string[] args)
{
timer = new Timer();
timer.Interval = 500;
timer.OnTimerTick += timerTick;
Thread timerThread = timer.Start();
for (; ; )
Thread.Sleep(5000);
}

And:

class Timer
{
// Delegates
public delegate void Tick();

// Properties
public int Interval;
public Tick OnTimerTick;

// Private Data
Thread _timerThread;
volatile bool _bStop;

public void SleepIntermittently(int totalTime)
{
int sleptTime = 0;
int intermittentSleepIncrement = 10;

while (!_bStop && sleptTime < totalTime)
{
Thread.Sleep(intermittentSleepIncrement);
sleptTime += intermittentSleepIncrement;
}
}

public void Run()
{
while (!_bStop)
{
// Sleep for the timer interval
SleepIntermittently(Interval);
// Then fire the tick event
OnTimerTick();
}
}

public Thread Start()
{
_bStop = false;
_timerThread = new Thread(new ThreadStart(Run));
_timerThread.IsBackground = true;
_timerThread.Start();
return _timerThread;
}

public void Stop()
{
// Request the loop to stop
_bStop = true;
_timerThread.Join(1000);
_timerThread.Abort();
}
}
 
P

Paul G. Tobey [eMVP]

It would be a good idea to know something about how a Windows program works
before you set off to write one. Read a chapter or two from the old Petzold
book, for example, Programming Windows. Chris is telling you that you can't
do what you want without a message pump, which is automatically there when
you build a forms-based application, but which does not exist in a console
application. So, you either need to build your application as forms-based
or you need to build your own message pump. If you want to do the latter
and stay as a console application, you must have a minimal understanding of
what a message pump is...

Paul T.

I don't know much about what are you talking about...please can you give me
any link?
Thanks..
"Chris Tacke, eMVP" <ctacke.at.opennetcf.dot.com> wrote in message
IIRC, it works via Windows Messages, so you have to have a message pump to
get the notifications. Sleep won't do it - you need to Get and Dispatch
messages from the queue.


--

Chris Tacke, Embedded MVP
OpenNETCF Consulting
Giving back to the embedded community
http://community.OpenNETCF.com



http://blog.opennetcf.com/ctacke/2008/10/20/TheCuttingRoomDetectingPOOMChanges.aspx
Thank you very much. It is very useful!!
It works with windows form but I'm not able to integrate it into my
console application.
Please, I need help! Where I should put this code?
POOMHelper.OutlookItemChanged += new
OutlookItemChangeDelegate(POOMHelper_OutlookItemChanged);

void POOMHelper_OutlookItemChanged(PIMNotificationMessage notification,
PIMItemType itemType, int itemOID, int databaseOID)

{

switch (itemType)

{

case PIMItemType.Calendar:

{...}

break;}}


My Console application:

class Program
{
static Timer timer= new Timer();
static void Main(string[] args)
{
timer = new Timer();
timer.Interval = 500;
timer.OnTimerTick += timerTick;
Thread timerThread = timer.Start();
for (; ; )
Thread.Sleep(5000);
}

And:

class Timer
{
// Delegates
public delegate void Tick();

// Properties
public int Interval;
public Tick OnTimerTick;

// Private Data
Thread _timerThread;
volatile bool _bStop;

public void SleepIntermittently(int totalTime)
{
int sleptTime = 0;
int intermittentSleepIncrement = 10;

while (!_bStop && sleptTime < totalTime)
{
Thread.Sleep(intermittentSleepIncrement);
sleptTime += intermittentSleepIncrement;
}
}

public void Run()
{
while (!_bStop)
{
// Sleep for the timer interval
SleepIntermittently(Interval);
// Then fire the tick event
OnTimerTick();
}
}

public Thread Start()
{
_bStop = false;
_timerThread = new Thread(new ThreadStart(Run));
_timerThread.IsBackground = true;
_timerThread.Start();
return _timerThread;
}

public void Stop()
{
// Request the loop to stop
_bStop = true;
_timerThread.Join(1000);
_timerThread.Abort();
}
}
 
S

Sam

Thanks...I'll read these chapters....

"Paul G. Tobey [eMVP]" <p space tobey no spam AT no instrument no spam DOT
com> wrote in message news:[email protected]...
It would be a good idea to know something about how a Windows program
works before you set off to write one. Read a chapter or two from the old
Petzold book, for example, Programming Windows. Chris is telling you that
you can't do what you want without a message pump, which is automatically
there when you build a forms-based application, but which does not exist
in a console application. So, you either need to build your application
as forms-based or you need to build your own message pump. If you want to
do the latter and stay as a console application, you must have a minimal
understanding of what a message pump is...

Paul T.

I don't know much about what are you talking about...please can you give
me any link?
Thanks..
"Chris Tacke, eMVP" <ctacke.at.opennetcf.dot.com> wrote in message
IIRC, it works via Windows Messages, so you have to have a message pump
to get the notifications. Sleep won't do it - you need to Get and
Dispatch messages from the queue.


--

Chris Tacke, Embedded MVP
OpenNETCF Consulting
Giving back to the embedded community
http://community.OpenNETCF.com



http://blog.opennetcf.com/ctacke/2008/10/20/TheCuttingRoomDetectingPOOMChanges.aspx
Thank you very much. It is very useful!!
It works with windows form but I'm not able to integrate it into my
console application.
Please, I need help! Where I should put this code?
POOMHelper.OutlookItemChanged += new
OutlookItemChangeDelegate(POOMHelper_OutlookItemChanged);

void POOMHelper_OutlookItemChanged(PIMNotificationMessage notification,
PIMItemType itemType, int itemOID, int databaseOID)

{

switch (itemType)

{

case PIMItemType.Calendar:

{...}

break;}}


My Console application:

class Program
{
static Timer timer= new Timer();
static void Main(string[] args)
{
timer = new Timer();
timer.Interval = 500;
timer.OnTimerTick += timerTick;
Thread timerThread = timer.Start();
for (; ; )
Thread.Sleep(5000);
}

And:

class Timer
{
// Delegates
public delegate void Tick();

// Properties
public int Interval;
public Tick OnTimerTick;

// Private Data
Thread _timerThread;
volatile bool _bStop;

public void SleepIntermittently(int totalTime)
{
int sleptTime = 0;
int intermittentSleepIncrement = 10;

while (!_bStop && sleptTime < totalTime)
{
Thread.Sleep(intermittentSleepIncrement);
sleptTime += intermittentSleepIncrement;
}
}

public void Run()
{
while (!_bStop)
{
// Sleep for the timer interval
SleepIntermittently(Interval);
// Then fire the tick event
OnTimerTick();
}
}

public Thread Start()
{
_bStop = false;
_timerThread = new Thread(new ThreadStart(Run));
_timerThread.IsBackground = true;
_timerThread.Start();
return _timerThread;
}

public void Stop()
{
// Request the loop to stop
_bStop = true;
_timerThread.Join(1000);
_timerThread.Abort();
}
}
 
S

Simon Hart [MVP]

As everyone else has suggested you need a windows pump (loop) to process
Windows Messages. Now you mentioned you were using a console app. You could
put this code in a windows app but write you're own message pump class if
you didn't want a UI but you wanted comunication with the windows subsystem.

You may have found out that the Application.Run method sets the forms
visible property to true showing the form which is undesired in some
situations. So if you write your own pump you can configure whether your
form is displayed or not. This will allow you to respond to windows messages
while at the same time have an application that runs without a UI. I think
there might be a custom pump class available in the SDF that allows you to
configure this - not sure.

--
Simon Hart
Visual Developer - Device Application Development MVP
http://www.simonrhart.com

Sam said:
Thanks...I'll read these chapters....

"Paul G. Tobey [eMVP]" <p space tobey no spam AT no instrument no spam DOT
com> wrote in message news:[email protected]...
It would be a good idea to know something about how a Windows program
works before you set off to write one. Read a chapter or two from the
old Petzold book, for example, Programming Windows. Chris is telling you
that you can't do what you want without a message pump, which is
automatically there when you build a forms-based application, but which
does not exist in a console application. So, you either need to build
your application as forms-based or you need to build your own message
pump. If you want to do the latter and stay as a console application,
you must have a minimal understanding of what a message pump is...

Paul T.

I don't know much about what are you talking about...please can you give
me any link?
Thanks..
"Chris Tacke, eMVP" <ctacke.at.opennetcf.dot.com> wrote in message
IIRC, it works via Windows Messages, so you have to have a message pump
to get the notifications. Sleep won't do it - you need to Get and
Dispatch messages from the queue.


--

Chris Tacke, Embedded MVP
OpenNETCF Consulting
Giving back to the embedded community
http://community.OpenNETCF.com



http://blog.opennetcf.com/ctacke/2008/10/20/TheCuttingRoomDetectingPOOMChanges.aspx
Thank you very much. It is very useful!!
It works with windows form but I'm not able to integrate it into my
console application.
Please, I need help! Where I should put this code?
POOMHelper.OutlookItemChanged += new
OutlookItemChangeDelegate(POOMHelper_OutlookItemChanged);

void POOMHelper_OutlookItemChanged(PIMNotificationMessage
notification, PIMItemType itemType, int itemOID, int databaseOID)

{

switch (itemType)

{

case PIMItemType.Calendar:

{...}

break;}}


My Console application:

class Program
{
static Timer timer= new Timer();
static void Main(string[] args)
{
timer = new Timer();
timer.Interval = 500;
timer.OnTimerTick += timerTick;
Thread timerThread = timer.Start();
for (; ; )
Thread.Sleep(5000);
}

And:

class Timer
{
// Delegates
public delegate void Tick();

// Properties
public int Interval;
public Tick OnTimerTick;

// Private Data
Thread _timerThread;
volatile bool _bStop;

public void SleepIntermittently(int totalTime)
{
int sleptTime = 0;
int intermittentSleepIncrement = 10;

while (!_bStop && sleptTime < totalTime)
{
Thread.Sleep(intermittentSleepIncrement);
sleptTime += intermittentSleepIncrement;
}
}

public void Run()
{
while (!_bStop)
{
// Sleep for the timer interval
SleepIntermittently(Interval);
// Then fire the tick event
OnTimerTick();
}
}

public Thread Start()
{
_bStop = false;
_timerThread = new Thread(new ThreadStart(Run));
_timerThread.IsBackground = true;
_timerThread.Start();
return _timerThread;
}

public void Stop()
{
// Request the loop to stop
_bStop = true;
_timerThread.Join(1000);
_timerThread.Abort();
}
}
 
C

Chris Tacke, eMVP

The SDF has a pump that can run with no Form at all (Application2.Run()),
with a Form that doesn't get shown(Application2.Run(new MyForm(), false)) or
like the normal one in the CF (Application2.Run(new MyForm())).


--

Chris Tacke, Embedded MVP
OpenNETCF Consulting
Giving back to the embedded community
http://community.OpenNETCF.com


Simon Hart said:
As everyone else has suggested you need a windows pump (loop) to process
Windows Messages. Now you mentioned you were using a console app. You
could put this code in a windows app but write you're own message pump
class if you didn't want a UI but you wanted comunication with the windows
subsystem.

You may have found out that the Application.Run method sets the forms
visible property to true showing the form which is undesired in some
situations. So if you write your own pump you can configure whether your
form is displayed or not. This will allow you to respond to windows
messages while at the same time have an application that runs without a
UI. I think there might be a custom pump class available in the SDF that
allows you to configure this - not sure.

--
Simon Hart
Visual Developer - Device Application Development MVP
http://www.simonrhart.com

Sam said:
Thanks...I'll read these chapters....

"Paul G. Tobey [eMVP]" <p space tobey no spam AT no instrument no spam
DOT com> wrote in message news:[email protected]...
It would be a good idea to know something about how a Windows program
works before you set off to write one. Read a chapter or two from the
old Petzold book, for example, Programming Windows. Chris is telling
you that you can't do what you want without a message pump, which is
automatically there when you build a forms-based application, but which
does not exist in a console application. So, you either need to build
your application as forms-based or you need to build your own message
pump. If you want to do the latter and stay as a console application,
you must have a minimal understanding of what a message pump is...

Paul T.

I don't know much about what are you talking about...please can you give
me any link?
Thanks..
"Chris Tacke, eMVP" <ctacke.at.opennetcf.dot.com> wrote in message
IIRC, it works via Windows Messages, so you have to have a message pump
to get the notifications. Sleep won't do it - you need to Get and
Dispatch messages from the queue.


--

Chris Tacke, Embedded MVP
OpenNETCF Consulting
Giving back to the embedded community
http://community.OpenNETCF.com




http://blog.opennetcf.com/ctacke/2008/10/20/TheCuttingRoomDetectingPOOMChanges.aspx
Thank you very much. It is very useful!!
It works with windows form but I'm not able to integrate it into my
console application.
Please, I need help! Where I should put this code?
POOMHelper.OutlookItemChanged += new
OutlookItemChangeDelegate(POOMHelper_OutlookItemChanged);

void POOMHelper_OutlookItemChanged(PIMNotificationMessage
notification, PIMItemType itemType, int itemOID, int databaseOID)

{

switch (itemType)

{

case PIMItemType.Calendar:

{...}

break;}}


My Console application:

class Program
{
static Timer timer= new Timer();
static void Main(string[] args)
{
timer = new Timer();
timer.Interval = 500;
timer.OnTimerTick += timerTick;
Thread timerThread = timer.Start();
for (; ; )
Thread.Sleep(5000);
}

And:

class Timer
{
// Delegates
public delegate void Tick();

// Properties
public int Interval;
public Tick OnTimerTick;

// Private Data
Thread _timerThread;
volatile bool _bStop;

public void SleepIntermittently(int totalTime)
{
int sleptTime = 0;
int intermittentSleepIncrement = 10;

while (!_bStop && sleptTime < totalTime)
{
Thread.Sleep(intermittentSleepIncrement);
sleptTime += intermittentSleepIncrement;
}
}

public void Run()
{
while (!_bStop)
{
// Sleep for the timer interval
SleepIntermittently(Interval);
// Then fire the tick event
OnTimerTick();
}
}

public Thread Start()
{
_bStop = false;
_timerThread = new Thread(new ThreadStart(Run));
_timerThread.IsBackground = true;
_timerThread.Start();
return _timerThread;
}

public void Stop()
{
// Request the loop to stop
_bStop = true;
_timerThread.Join(1000);
_timerThread.Abort();
}
}
 
S

Simon Hart [MVP]

That's cool, I need to check that out sometime.

--
Simon Hart
Visual Developer - Device Application Development MVP
http://www.simonrhart.com


Chris Tacke said:
The SDF has a pump that can run with no Form at all (Application2.Run()),
with a Form that doesn't get shown(Application2.Run(new MyForm(), false)) or
like the normal one in the CF (Application2.Run(new MyForm())).


--

Chris Tacke, Embedded MVP
OpenNETCF Consulting
Giving back to the embedded community
http://community.OpenNETCF.com


Simon Hart said:
As everyone else has suggested you need a windows pump (loop) to process
Windows Messages. Now you mentioned you were using a console app. You
could put this code in a windows app but write you're own message pump
class if you didn't want a UI but you wanted comunication with the windows
subsystem.

You may have found out that the Application.Run method sets the forms
visible property to true showing the form which is undesired in some
situations. So if you write your own pump you can configure whether your
form is displayed or not. This will allow you to respond to windows
messages while at the same time have an application that runs without a
UI. I think there might be a custom pump class available in the SDF that
allows you to configure this - not sure.

--
Simon Hart
Visual Developer - Device Application Development MVP
http://www.simonrhart.com

Sam said:
Thanks...I'll read these chapters....

"Paul G. Tobey [eMVP]" <p space tobey no spam AT no instrument no spam
DOT com> wrote in message It would be a good idea to know something about how a Windows program
works before you set off to write one. Read a chapter or two from the
old Petzold book, for example, Programming Windows. Chris is telling
you that you can't do what you want without a message pump, which is
automatically there when you build a forms-based application, but which
does not exist in a console application. So, you either need to build
your application as forms-based or you need to build your own message
pump. If you want to do the latter and stay as a console application,
you must have a minimal understanding of what a message pump is...

Paul T.

I don't know much about what are you talking about...please can you give
me any link?
Thanks..
"Chris Tacke, eMVP" <ctacke.at.opennetcf.dot.com> wrote in message
IIRC, it works via Windows Messages, so you have to have a message pump
to get the notifications. Sleep won't do it - you need to Get and
Dispatch messages from the queue.


--

Chris Tacke, Embedded MVP
OpenNETCF Consulting
Giving back to the embedded community
http://community.OpenNETCF.com




http://blog.opennetcf.com/ctacke/2008/10/20/TheCuttingRoomDetectingPOOMChanges.aspx
Thank you very much. It is very useful!!
It works with windows form but I'm not able to integrate it into my
console application.
Please, I need help! Where I should put this code?
POOMHelper.OutlookItemChanged += new
OutlookItemChangeDelegate(POOMHelper_OutlookItemChanged);

void POOMHelper_OutlookItemChanged(PIMNotificationMessage
notification, PIMItemType itemType, int itemOID, int databaseOID)

{

switch (itemType)

{

case PIMItemType.Calendar:

{...}

break;}}


My Console application:

class Program
{
static Timer timer= new Timer();
static void Main(string[] args)
{
timer = new Timer();
timer.Interval = 500;
timer.OnTimerTick += timerTick;
Thread timerThread = timer.Start();
for (; ; )
Thread.Sleep(5000);
}

And:

class Timer
{
// Delegates
public delegate void Tick();

// Properties
public int Interval;
public Tick OnTimerTick;

// Private Data
Thread _timerThread;
volatile bool _bStop;

public void SleepIntermittently(int totalTime)
{
int sleptTime = 0;
int intermittentSleepIncrement = 10;

while (!_bStop && sleptTime < totalTime)
{
Thread.Sleep(intermittentSleepIncrement);
sleptTime += intermittentSleepIncrement;
}
}

public void Run()
{
while (!_bStop)
{
// Sleep for the timer interval
SleepIntermittently(Interval);
// Then fire the tick event
OnTimerTick();
}
}

public Thread Start()
{
_bStop = false;
_timerThread = new Thread(new ThreadStart(Run));
_timerThread.IsBackground = true;
_timerThread.Start();
return _timerThread;
}

public void Stop()
{
// Request the loop to stop
_bStop = true;
_timerThread.Join(1000);
_timerThread.Abort();
}
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top