Welcome to the new FlexRadio Community! Please review the new Community Rules and other important new Community information on the Message Board.
Need the latest SmartSDR, Power Genius, Tuner Genius and Antenna Genius Software?
SmartSDR v3.8.19 and the SmartSDR v3.8.19 Release Notes | SmartSDR v2.12.1 and the SmartSDR v2.12.1 Release Notes
SmartSDR v1.12.1 and the SmartSDR v1.12.1 Release Notes
Power Genius XL Utility v3.8.8 and the Power Genius XL Release Notes v3.8.8
Tuner Genius XL Utility v1.2.11 and the Tuner Genius XL Release Notes v1.2.11
Antenna Genius Utility v4.1.8
SmartSDR v3.8.19 and the SmartSDR v3.8.19 Release Notes | SmartSDR v2.12.1 and the SmartSDR v2.12.1 Release Notes
SmartSDR v1.12.1 and the SmartSDR v1.12.1 Release Notes
Power Genius XL Utility v3.8.8 and the Power Genius XL Release Notes v3.8.8
Tuner Genius XL Utility v1.2.11 and the Tuner Genius XL Release Notes v1.2.11
Antenna Genius Utility v4.1.8
If you are having a problem, please refer to the product documentation or check the Help Center for known solutions.
Need technical support from FlexRadio? It's as simple as Creating a HelpDesk ticket.
Need technical support from FlexRadio? It's as simple as Creating a HelpDesk ticket.
VS Examples
Mark Erbaugh
Member ✭✭
With the FlexLib download is a ComPTT project, which I assume is an example on how to use the library, but it's not enough for me to get started.
I tried to do something simple, like set the title of the main window to the radio's Nickname. In the API_RadioAdded event handler, I added the line Text = radio.nickname, but when I run it, I get an exception about cross-thread operation not valid.
This may be a windows programming thing, rather than a FlexLib thing, but for a newbie to Visual Studio programming a more complete example would be helpful. Maybe someone could even give step by step instructions on how to get started with FlexLib and VS.
One post I found in the forum said to search the forum and there were lots of examples, but I haven't been able to find any.
I tried to do something simple, like set the title of the main window to the radio's Nickname. In the API_RadioAdded event handler, I added the line Text = radio.nickname, but when I run it, I get an exception about cross-thread operation not valid.
This may be a windows programming thing, rather than a FlexLib thing, but for a newbie to Visual Studio programming a more complete example would be helpful. Maybe someone could even give step by step instructions on how to get started with FlexLib and VS.
One post I found in the forum said to search the forum and there were lots of examples, but I haven't been able to find any.
1
Answers
-
I haven't looked at that program but typical in Windows is having to marshal information back to the GUI thread. The GUI is single threaded so you would typically create a new thread for other processes to run on. When you try to update the GUI from that thread you get the cross thread error.
I have a little method I use in all my GUI programs to marshal the information back to the GUI.
private void UpdateLabel(string message) {
if (InvokeRequired)
{
this.BeginInvoke(new Action<string>(this.UpdateLabel), message);
return;
}
LabelProgress.Enabled = true;
LabelProgress.Visible = true;
LabelProgress.Text = message;
}
Just put your Text = radio.nickname in there instead of what I have.
73,
Pete1 -
Pete,
Thanks for the reply. I found some stuff on MS' website that used a delegate. Is that different from the Action you used? Does the Action have to be allocated each time, or could you allocate it once and re-use it?
0 -
A don't believe a delegate is what you want. With the method I provided you need to call it every time you update the GUI. If you have multiple labels you want to update you can always put a switch statement in it. You can change the method signature as needed.
private void UpdateListViewLoad(string message, string status, bool clear){
if (InvokeRequired)
{
this.BeginInvoke(new Action<string, string, bool>(this.UpdateListViewLoad), message, status, clear);
return;
}
// syntax approximate - I switch between Swift and C# all day and its hard to keep it
// straight sometimes
switch (status) {
case "active":
... do something
case "inactive":
... do something
}
Actually I would use an enum for status.
0 -
I'm not sure you need to remove the property change handler. C# does a pretty good job of cleaning up after itself. Probably the property changed after the handler was removed. You may need to disconnect or dispose of the radio object or whatever is changing the property. If I have time I'll look at the code Flex provided.0
-
I just posted in another thread about this. It depends completely on your use. If the event handler remains alive during the entire life of your app then not removing it is fine.
But if you open a window, then close it and the open sets an event handler but does not remove it. I have seen some VERY STRANGE behavior with this scenario.1 -
Mark,
Feel free to email me at ws7m@arrl.net if you need some help at times.0 -
Yes, I should have given a more comprehensive explanation.0
-
What's the difference between Action and delegate. If you do a Peek definition on Action, it displays code from System.Core that just says public delegate void Action()
Secondly, your code calls new every time you call this.BeginInvoke. Would it be more resource efficient to create a variable of type Action<string,string,bool> and do the new once in the object's constructor and then just reference that object?
0 -
You know, I’ve been using that code for so long I have never thought much about it. That would be a good question to post on stackoverflow. As far as efficiency, if it’s not in a loop it really doesn’t matter much.0
Leave a Comment
Categories
- All Categories
- 289 Community Topics
- 2.1K New Ideas
- 534 The Flea Market
- 7.5K Software
- 6K SmartSDR for Windows
- 146 SmartSDR for Maestro and M models
- 360 SmartSDR for Mac
- 249 SmartSDR for iOS
- 230 SmartSDR CAT
- 172 DAX
- 352 SmartSDR API
- 8.8K Radios and Accessories
- 7K FLEX-6000 Signature Series
- 26 FLEX-8000 Signature Series
- 850 Maestro
- 44 FlexControl
- 847 FLEX Series (Legacy) Radios
- 796 Genius Products
- 416 Power Genius XL Amplifier
- 277 Tuner Genius XL
- 103 Antenna Genius
- 243 Shack Infrastructure
- 166 Networking
- 404 Remote Operation (SmartLink)
- 130 Contesting
- 631 Peripherals & Station Integration
- 125 Amateur Radio Interests
- 870 Third-Party Software