- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi fellas, i was hoping somebody could help me out.
I am using the Intel Mobile SDK 1.2 in order to access powerevents when the power is connected and disconnected.
Currently i have the events registering and a message box poping up when this happens, but i want to be able to log the events to a text box on my windows form, also i want to be able to re-size a picture when the power is disconnected, and then make it larger when power is connected again (power saving)but i cannot do either of these, it just seems to be the message box that pops up. I am using C#
Any ideas as to why this is not working for me, i have access to everything when the form.
here is my code:
thanks fellas,
PS my form is [MTATHREAD]
using
System;using
System.Collections.Generic;using
System.ComponentModel;using
System.Data;using
System.Drawing;using
System.Text;using
System.Windows.Forms;using
System.Threading;using
Intel.Mobile.Base;using
Intel.Mobile.Battery;using
Intel.Mobile.Context;namespace
PowerExample{
public partial class Form2 : Form{
ContextClass myClass = new ContextClass(); public PowerInstance myInstance; internal static bool LoopFlag = true; internal static readonly System.Object Mutex = new System.Object(); private DelegateObserver.ObserverNotifyDelegate DisconnectNotifyDelegate = null;public Form2()
{
InitializeComponent();
myInstance = (
PowerInstance)myClass.GetInstance(
"Power"); DelegateObserver.ObserverNotifyDelegate del = new DelegateObserver.ObserverNotifyDelegate(ConnectedEventHandler); Observer connectedChangeObsvr = new DelegateObserver(del);myInstance.ExternallyPowered.AddObserver(connectedChangeObsvr);
myInstance.InternallyPowered.AddObserver(connectedChangeObsvr);
}
private void ConnectedEventHandler(Event eEvent){
try{
if (eEvent.GetType() == EventBase.EventType.eExternallyPowered){
//textBox1.AppendText("Connected 1 " + DateTime.Now); MessageBox.Show("Ac Adapter Connectd"); //textBox1.AppendText("Conneted 2 " + DateTime.Now);}
if(eEvent.GetType() == EventBase.EventType.eInternallyPowered){
//textBox1.AppendText("Disconnect 1 " + DateTime.Now); MessageBox.Show("Ac Adapter Disconnected"); //textBox1.AppendText("Disconnect 2 " + DateTime.Now);}
}
catch (IntelMobileException ex){
textBox1.Text = (ex.ToString());
}
catch (Exception e){
textBox1.Text = (
"------------ Exception Occurred ------------");textBox1.Text = (
"Message: " + e.Message);textBox1.Text = (
"Source: " + e.Source);textBox1.Text = (
"Target Site: " + e.TargetSite);}
}
}
internal class DelegateObserver : Observer{
public delegate void ObserverNotifyDelegate(Event eEvent); public DelegateObserver(ObserverNotifyDelegate Notifydelegate){
this.MyNotifydelegate = Notifydelegate;}
public override void Notify(Event ev){
this.MyNotifydelegate(ev);}
private ObserverNotifyDelegate MyNotifydelegate;}
}
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi, I have reproduced your problem. Because the event notification is a separate thread, it seems in a new thread that can't directlyinteract with the control created by the main thread. Just like creating a new thread and you will meet the same problem.
I will investigate more and get you later for the solution in such case.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
thanks for getting back to me with that friend, id be reallly greatful if you could sort of a soultion for me or point me in the rigth direction to sort it myself as i have never used threading before.
thanks again for your help and i look forward to hearing from you again
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi, this is about Multitheaded Windows Forms Control as you are using event notification in MPSDK. MSDN has the detail ms-help://MS.MSDNQTR.2005JAN.1033/cpguide/html/cpco
nDevelopingMultithreadedWindowsFormsControl.htm
Hereis the samplesolution (part of code)in your case, to add one delegate and marshal the calling to Windows control in multi-threading. Please note the string is passed instead of event object during marshalling.
public partial class Form2 : Form
{
...
delegate void LogDelegate(string str);
LogDelegate logHandler;
public Form2()
{
logHandler = new LogDelegate(LogEvent);
...
}
private void ConnectedEventHandler(Event eEvent)
{
try
{
if (eEvent.GetType() == EventBase.EventType.eExternallyPowered)
{
this.BeginInvoke(logHandler, new object[] { "Connected" });
}
if (eEvent.GetType() == EventBase.EventType.eInternallyPowered)
{
this.BeginInvoke(logHandler, new object[] { "Disconnected" });
}
}
catch (IntelMobileException ex)
{
...
}
catch (Exception e)
{
...
}
}
private void LogEvent(string acType)
{
tex
tBox1.AppendText(acType + " " + DateTime.Now);
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
worked perferct my friend thank you very much
i have one additionl query for you if you do not mind
i would like to add in windows media player into my app but it will only allow to play in single thread apps, is there any way round this?
many thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
worked perferct my friend thank you very much
i have one additionl query for you if you do not mind
i would like to add in windows media player into my app but it will only allow to play in single thread apps, is there any way round this?
many thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi, I don't know how Windows Media Player works here. If you wantto get events asynchronously in MPSDK, it only supports multi-thread applications.
You can consider inter-process communication for your single thread app.
-Bin
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page