473,382 Members | 1,639 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

Multithreading/GPS

markmcgookin
648 Expert 512MB
Hi,

This is a question re: a mobile development project, however I feel my issue is C# based and not anything to do with the mobile side of thigs, so I will leave this post here (as I feel it'll get a better responce)

Right... here we go:

I have an application based on a MS Sample for using GPS on a PDA. It works fine! (Woohoo!) It is using the Microsoft.WindowsMobile.Samples.Location project classes as it's base. These classes use multithreading

Expand|Select|Wrap|Line Numbers
  1. // Create and start thread to listen for GPS events
  2.                 gpsEventThread = new System.Threading.Thread(new System.Threading.ThreadStart(WaitForGpsEvents));
  3.                 gpsEventThread.Start();
  4.  
which is fine, because in my sample app I just create a new GPS() and then I can talk to it.... However this isn't practical in my full blown app that I want to implement this GPS into, as I don't want to put the reams of GPS code in every form (as I need to log the position of the user at various points, i.e. when forms are loaded) the sample uses a lot of custom event handlers etc for some reason, to pass arguments etc, and this is where I start to get a bit hazey. Basically what i want to do is create a new GPS instance/object when the app is run, and for each other form that is opened talk to this GPS and find out my position. Currently when they are all in the same form the code looks like this

Expand|Select|Wrap|Line Numbers
  1.         private EventHandler updateDataHandler;
  2.         Gps gps = new Gps();
  3.         GpsPosition position = null;
  4.         GpsDeviceState device = null;
  5.  
  6. ...... 
  7.  
  8. private void menuItem2_Click(object sender, EventArgs e)
  9.         {
  10.             try
  11.             {
  12.                 Invoke(updateDataHandler);
  13.             }
  14.  
  15. .......
  16.  
  17. private void Form1_Load(object sender, EventArgs e)
  18.         {
  19.             updateDataHandler = new EventHandler(updateData);
  20.  
  21.             label1.Text = "";
  22.  
  23.             gps.DeviceStateChanged += new DeviceStateChangedEventHandler(gps_DeviceStateChanged);
  24.             gps.LocationChanged += new LocationChangedEventHandler(gps_LocationChanged);
  25.         }
  26.  
  27.         void gps_LocationChanged(object sender, LocationChangedEventArgs args)
  28.         {
  29.             position = args.Position;
  30.         }
  31.  
  32.         void gps_DeviceStateChanged(object sender, DeviceStateChangedEventArgs args)
  33.         {
  34.             device = args.DeviceState;
  35.         }
  36.  
  37.         void updateData(object sender, System.EventArgs args)
  38.         {
  39.             Cursor.Current = Cursors.WaitCursor;
  40.  
  41.             if (gps.Opened)
  42.             {
  43.                 string str = "";
  44.  
  45.                 if (device != null)
  46.                 {
  47.                     str = device.FriendlyName + " " + device.ServiceState + ", " + device.DeviceState + "\n";
  48.                 }
  49.                 else
  50.                 {
  51.                     fullData = false;
  52.                 }
  53.  
  54.                 if (position != null)
  55.                 {
  56.                     if (position.LatitudeValid)
  57.                     {
  58.                         str += "Latitude (DD): \n " + position.Latitude + "\n";
  59.                         str += "Latitude (D,M,S): \n " + position.LongitudeInDegreesMinutesSeconds + "\n";
  60.                         myGPSData.Lattitude = position.Latitude.ToString();
  61.                     }
  62.  
this type of thing goes on and on... now when I just tried to stick all this in a class by itself, it all seemed fine but whenever I tried the "Invoke" method to kick off the event handler, I was told that "Invoke does not exist in the current context" and I really dont know what is going on.

I want my GPS to be started on the login form opening, and be able to pull it's position whenever I want using a method off various forms, and close the GPS on the applcation exiting. So essentially have it running, fully functional in the background.

Sorry for such a long post, but I like to get my point accross clearly, and help with how I should do this?

Cheers,

Mark
Sep 10 '07 #1
1 1420
Plater
7,872 Expert 4TB
That Invoke call that you see is really being mapped to this.Invoke() which probably goes to like form1.Invoke() (Invoke is from the Control object)
It's used like you said to force an event to occur.

If you want a better understanding of it, look up events/delegates in the msdn.

Suffice to say you be able to just call the function when you have your own class for it. It looks like they did that just to make sure it was mutli-threaded?
Sep 10 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: dixp | last post by:
I'm new to writing multithreaded apps and I have a design question. I have a winforms app and a class which has a method that does processing which is time intensive. I want the user to be able...
47
by: mihai | last post by:
What does the standard say about those two? Is any assurance that the use of STL is thread safe? Have a nice day, Mihai.
16
by: Robert Zurer | last post by:
Can anyone suggest the best book or part of a book on this subject. I'm looking for an in-depth treatment with examples in C# TIA Robert Zurer robert@zurer.com
5
by: sarge | last post by:
I would like to know how to perform simple multithreading. I had created a simple form to test out if I was multithreading properly, but got buggy results. Sometime the whole thig would lock up...
9
by: tommy | last post by:
hi, i have found a example for multithreading and asp.net http://www.fawcette.com/vsm/2002_11/magazine/features/chester/ i want to speed up my website ... if my website is starting, they...
2
by: Rich | last post by:
Hello, I have set up a multithreading routine in a Test VB.net proj, and it appears to be working OK in debug mode and I am not using synchronization. Multithreading is a new thing for me, and...
55
by: Sam | last post by:
Hi, I have a serious issue using multithreading. A sample application showing my issue can be downloaded here: http://graphicsxp.free.fr/WindowsApplication11.zip The problem is that I need to...
5
by: sandy82 | last post by:
Whats actuallly multithreading is ... and how threading and multithreading differ . Can any1 guide how multithreading is used on the Web .. i mean a practical scenario in which u use...
2
by: Pradnya Patil | last post by:
hi , I am trying to draw ' html div-tag ' on the screen which will resemble a rectangle through vb.net code. I want it to be drawn faster...so I introduced multithreading using Threadpool. I...
7
by: Ray | last post by:
Hello, Greetings! I'm looking for a solid C++ multithreading book. Can you recommend one? I don't think I've seen a multithreading C++ book that everybody thinks is good (like Effective C++ or...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.