|
I'm am puzzled by this:
1. I have a Dictionary whose Keys are Enumeration-Values, and whose Values are of Type Action<Control1, Control2>
2. At run-time I am calling a method that adds a LocationChanged EventHandler which is constructed as a lambda on-the-fly ... to Control1. This LocationChanged EventHandler will execute the Action described in #1 which will change the other Control, Control2.
When Control2 refers to a Form, and, at run-time, that Form has been closed using its Close Button: my impression, up to now, has been that references to that Form would be garbage collected, so if Control1 (another Form) was moved, and the LocationChanged event was triggered which attempted to modify Control1 (closed Form), I would expect a null reference error.
But, there is no run-time error thrown; I infer from that there must be valid references to the closed Form "still around."
I think I better illustrate this with a dumbed-down bare-bones code example: a WinForms project with a MainForm 'Form1, and second Form, 'Form2:
enum SomeEnum
{
whatever1,
whatever2
}
private Dictionary<SomeEnum, Action<Control, Control>> EnumToAction;
private void Form1_Load(object sender, EventArgs e)
{
EnumToAction = new Dictionary<SomeEnum, Action<Control, Control>>
{
{
SomeEnum.whatever1, (control, control1) =>
{
control1.Top = control.Top;
}
},
{
SomeEnum.whatever2, (control, control1) =>
{
control1.Left = control.Right;
}
}
};
Form2 f2 = new Form2();
f2.Show();
SetAction(this, f2, SomeEnum.whatever1);
}
private void SetAction(Control bControl, Control dControl, SomeEnum someenum)
{
bControl.LocationChanged += (sender, args) =>
{
EnumToAction[someenum](bControl, dControl);
};
EnumToAction[someenum](bControl, dControl);
} Running the above code, then closing 'Form2 by clicking its Form Close Button, and then moving 'Form1 does not then throw an error which makes me believe that the reference to 'Form2 in that created-lambda EventHandler must still be valid.
I guess I could keep a Dictionary of Control, EventHandler around to deal with this ... to explicitly remove EventHandlers ... but, then, you've got different types of EventHandlers (differences in parameters) to deal with.
Ideas ?
thanks, Bill
«I want to stay as close to the edge as I can without going over. Out on the edge you see all kinds of things you can't see from the center» Kurt Vonnegut.
modified 19-Jul-15 10:40am.
|
|
|
|
|
Everyone knows that anonymous delegates cannot be removed so obviously there are places where they should not be used!
But what if?
What if the add and remove mechanisms are set up at the same time? Sure the delegate code is anonymous but, as you say in your message, a reference can be kept.
I have lambdaphobia so here is the great idea in old school code.
public class Form1 : Form {
protected override void OnLoad(EventArgs e) {
base.OnLoad(e);
this.Text = "One";
Form f = new Form();
f.Text = "Two";
f.Show();
ISeeAWitch(this, f);
}
private void ISeeAWitch(Form bControl, Form dControl) {
EventHandler locationChanged = new EventHandler(delegate(Object sender, EventArgs e) {
dControl.Left = bControl.Right;
dControl.Top = bControl.Top;
});
bControl.LocationChanged += locationChanged;
dControl.FormClosed += new FormClosedEventHandler(delegate(Object sender, FormClosedEventArgs e) {
if (bControl != null) {
bControl.LocationChanged -= locationChanged;
MessageBox.Show("I'm off");
}
});
locationChanged(null, null);
}
}
Alan.
|
|
|
|
|
Thanks Alan, for this delightful code sample, and your comments.
I entertained the idea that the act of closing a Form at run-time might be somehow qualitatively different ... vis-a-vis garbage-collection ... than the act of disposing other objects. I'd say that was a poor choice of entertainment
I really like using Dictionaries whose keys are Enums and Values are executable code.
cheers, Bill
«I want to stay as close to the edge as I can without going over. Out on the edge you see all kinds of things you can't see from the center» Kurt Vonnegut.
|
|
|
|
|
Quote: Running the above code, then closing 'Form2 by clicking its Form Close Button, and then moving 'Form1 does not then throw an error which makes me believe that the reference to 'Form2 in that created-lambda EventHandler must still be valid.
What you are seeing is by design as the garbage collector makes the following guarantees:
1. Every object will be destroyed, and its destructor will be run. When a program ends, all remaining objects will be destroyed.
2. Every object will be destroyed exactly once.
3. Every object will be destroyed only when it becomes unreachable, i.e. when there are no references to the object in the process running your application.
The garbage collector works on its own thread and can execute only at certain times, while it runs other threads in you application are temporarily halted in case it needs to move obects around and update references.
Generally the following steps are taken by the garbage collector:
1. builds a map of the reachable objects
2. checks if any unreachable objects have a destructor that needs to be run (i.e finalization, if any are found they are moved to a special queue)
3. Deallocation of remaining unreachable objects, and moves reachable objects down the heap, updates any references to the reachable objects
4. allows other threads to resume
5. Runs the finalized methods from number 2
|
|
|
|
|
Thanks for your reply Member 11136461,
As I wrote in reply to Alan's comments: "I entertained the idea that the act of closing a Form at run-time might be somehow qualitatively different ... vis-a-vis garbage-collection ... than the act of disposing other objects. I'd say that was a poor choice of entertainment"
cheers, Bill
«I want to stay as close to the edge as I can without going over. Out on the edge you see all kinds of things you can't see from the center» Kurt Vonnegut.
|
|
|
|
|
I suspect the key is to look at what the compiler's doing behind the scenes.
Your anonymous LocationChanged handler closes over three parameters and an instance field, so the compiler will generate something like this:
private sealed class SetActionClosure
{
public Form1 @this;
public Control bControl;
public Control dControl;
public SomeEnum someenum;
public void AnonymousLocationChangedHandler(object sender, EventArgs e)
{
@this.EnumToAction[someenum](bControl, dControl);
}
}
private void SetActive(Control bControl , Control dControl , SomeEnum someenum)
{
SetActionClosure closure = new SetActionClosure();
closure.@this = this;
closure.bControl = bControl;
closure.dControl = dControl;
closure.someenum = someenum;
bControl .LocationChanged += closure.AnonymousLocationChangedHandler;
...
}
The instance of the closure class will remain alive as long as the event handler still has a reference to it - ie: until you unsubscribe the handler, or close the Form1 instance.
That closure class instance has a reference to the Form2 instance "f2 ". That Form2 instance will remain in alive for as long as the closure class instance remains alive.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Hi,
I have a simple Application using simple controls. I have deployed the application with all the libraries listed in the References but the application is crashing when I run it.
here is the log from Windows but I am not sure where is the problem!
="1.0"="UTF-16"
<DATABASE>
<EXE NAME="GOOPOS.exe" FILTER="CMI_FILTER_PRIVACY">
<MATCHING_FILE NAME="DevExpress.BonusSkins.v14.2.dll" SIZE="8921872" CHECKSUM="0xBB314D92" BIN_FILE_VERSION="14.2.7.0" BIN_PRODUCT_VERSION="14.2.7.0" PRODUCT_VERSION="14.2.7.0" FILE_DESCRIPTION="DevExpress.BonusSkins" COMPANY_NAME="Developer Express Inc." PRODUCT_NAME="DevExpress.BonusSkins" FILE_VERSION="14.2.7.0" ORIGINAL_FILENAME="DevExpress.BonusSkins.v14.2.dll" INTERNAL_NAME="DevExpress.BonusSkins.v14.2.dll" LEGAL_COPYRIGHT="Copyright (c) 2000-2014 Developer Express Inc." VERDATEHI="0x0" VERDATELO="0x0" VERFILEOS="0x4" VERFILETYPE="0x2" MODULE_TYPE="WIN32" PE_CHECKSUM="0x88A0A1" LINKER_VERSION="0x0" UPTO_BIN_FILE_VERSION="14.2.7.0" UPTO_BIN_PRODUCT_VERSION="14.2.7.0" LINK_DATE="04/21/2015 12:50:54" UPTO_LINK_DATE="04/21/2015 12:50:54" VER_LANGUAGE="Language Neutral [0x0]" EXE_WRAPPER="0x0" />
<MATCHING_FILE NAME="DevExpress.Data.v14.2.dll" SIZE="3602704" CHECKSUM="0xF350C5ED" BIN_FILE_VERSION="14.2.7.0" BIN_PRODUCT_VERSION="14.2.7.0" PRODUCT_VERSION="14.2.7.0" FILE_DESCRIPTION="DevExpress.Data" COMPANY_NAME="Developer Express Inc." PRODUCT_NAME="DevExpress.Data" FILE_VERSION="14.2.7.0" ORIGINAL_FILENAME="DevExpress.Data.v14.2.dll" INTERNAL_NAME="DevExpress.Data.v14.2.dll" LEGAL_COPYRIGHT="Copyright (c) 2000-2014 Developer Express Inc." VERDATEHI="0x0" VERDATELO="0x0" VERFILEOS="0x4" VERFILETYPE="0x2" MODULE_TYPE="WIN32" PE_CHECKSUM="0x37920D" LINKER_VERSION="0x0" UPTO_BIN_FILE_VERSION="14.2.7.0" UPTO_BIN_PRODUCT_VERSION="14.2.7.0" LINK_DATE="04/21/2015 12:50:10" UPTO_LINK_DATE="04/21/2015 12:50:10" VER_LANGUAGE="Language Neutral [0x0]" EXE_WRAPPER="0x0" />
<MATCHING_FILE NAME="DevExpress.Printing.v14.2.Core.dll" SIZE="3150608" CHECKSUM="0xCE3DD913" BIN_FILE_VERSION="14.2.7.0" BIN_PRODUCT_VERSION="14.2.7.0" PRODUCT_VERSION="14.2.7.0" FILE_DESCRIPTION="DevExpress.Printing.Core" COMPANY_NAME="Developer Express Inc." PRODUCT_NAME="DevExpress.Printing.Core" FILE_VERSION="14.2.7.0" ORIGINAL_FILENAME="DevExpress.Printing.v14.2.Core.dll" INTERNAL_NAME="DevExpress.Printing.v14.2.Core.dll" LEGAL_COPYRIGHT="Copyright (c) 2000-2014 Developer Express Inc." VERDATEHI="0x0" VERDATELO="0x0" VERFILEOS="0x4" VERFILETYPE="0x2" MODULE_TYPE="WIN32" PE_CHECKSUM="0x30A92C" LINKER_VERSION="0x0" UPTO_BIN_FILE_VERSION="14.2.7.0" UPTO_BIN_PRODUCT_VERSION="14.2.7.0" LINK_DATE="04/21/2015 12:50:36" UPTO_LINK_DATE="04/21/2015 12:50:36" VER_LANGUAGE="Language Neutral [0x0]" EXE_WRAPPER="0x0" />
<MATCHING_FILE NAME="DevExpress.Sparkline.v14.2.Core.dll" SIZE="77072" CHECKSUM="0xE7D24A7D" BIN_FILE_VERSION="14.2.7.0" BIN_PRODUCT_VERSION="14.2.7.0" PRODUCT_VERSION="14.2.7.0" FILE_DESCRIPTION="DevExpress.Sparkline.Core" COMPANY_NAME="Developer Express Inc." PRODUCT_NAME="DevExpress.Sparkline.Core" FILE_VERSION="14.2.7.0" ORIGINAL_FILENAME="DevExpress.Sparkline.v14.2.Core.dll" INTERNAL_NAME="DevExpress.Sparkline.v14.2.Core.dll" LEGAL_COPYRIGHT="Copyright (c) 2000-2014 Developer Express Inc." VERDATEHI="0x0" VERDATELO="0x0" VERFILEOS="0x4" VERFILETYPE="0x2" MODULE_TYPE="WIN32" PE_CHECKSUM="0x1A0AB" LINKER_VERSION="0x0" UPTO_BIN_FILE_VERSION="14.2.7.0" UPTO_BIN_PRODUCT_VERSION="14.2.7.0" LINK_DATE="04/21/2015 12:52:38" UPTO_LINK_DATE="04/21/2015 12:52:38" VER_LANGUAGE="Language Neutral [0x0]" EXE_WRAPPER="0x0" />
<MATCHING_FILE NAME="DevExpress.Utils.v14.2.dll" SIZE="5514000" CHECKSUM="0xF0348B91" BIN_FILE_VERSION="14.2.7.0" BIN_PRODUCT_VERSION="14.2.7.0" PRODUCT_VERSION="14.2.7.0" FILE_DESCRIPTION="DevExpress.Utils" COMPANY_NAME="Developer Express Inc." PRODUCT_NAME="DevExpress.Utils" FILE_VERSION="14.2.7.0" ORIGINAL_FILENAME="DevExpress.Utils.v14.2.dll" INTERNAL_NAME="DevExpress.Utils.v14.2.dll" LEGAL_COPYRIGHT="Copyright (c) 2000-2014 Developer Express Inc." VERDATEHI="0x0" VERDATELO="0x0" VERFILEOS="0x4" VERFILETYPE="0x2" MODULE_TYPE="WIN32" PE_CHECKSUM="0x548B79" LINKER_VERSION="0x0" UPTO_BIN_FILE_VERSION="14.2.7.0" UPTO_BIN_PRODUCT_VERSION="14.2.7.0" LINK_DATE="04/21/2015 12:50:46" UPTO_LINK_DATE="04/21/2015 12:50:46" VER_LANGUAGE="Language Neutral [0x0]" EXE_WRAPPER="0x0" />
<MATCHING_FILE NAME="DevExpress.XtraEditors.v14.2.dll" SIZE="4198672" CHECKSUM="0xED0C9351" BIN_FILE_VERSION="14.2.7.0" BIN_PRODUCT_VERSION="14.2.7.0" PRODUCT_VERSION="14.2.7.0" FILE_DESCRIPTION="DevExpress.XtraEditors" COMPANY_NAME="Developer Express Inc." PRODUCT_NAME="DevExpress.XtraEditors" FILE_VERSION="14.2.7.0" ORIGINAL_FILENAME="DevExpress.XtraEditors.v14.2.dll" INTERNAL_NAME="DevExpress.XtraEditors.v14.2.dll" LEGAL_COPYRIGHT="Copyright (c) 2000-2014 Developer Express Inc." VERDATEHI="0x0" VERDATELO="0x0" VERFILEOS="0x4" VERFILETYPE="0x2" MODULE_TYPE="WIN32" PE_CHECKSUM="0x408765" LINKER_VERSION="0x0" UPTO_BIN_FILE_VERSION="14.2.7.0" UPTO_BIN_PRODUCT_VERSION="14.2.7.0" LINK_DATE="04/21/2015 12:52:46" UPTO_LINK_DATE="04/21/2015 12:52:46" VER_LANGUAGE="Language Neutral [0x0]" EXE_WRAPPER="0x0" />
<MATCHING_FILE NAME="GOOPOS.exe" SIZE="79360" CHECKSUM="0xD965F83F" BIN_FILE_VERSION="1.0.0.0" BIN_PRODUCT_VERSION="1.0.0.0" PRODUCT_VERSION="1.0.0.0" FILE_DESCRIPTION="OPOS_Sample" PRODUCT_NAME="OPOS_Sample" FILE_VERSION="1.0.0.0" ORIGINAL_FILENAME="GOOPOS.exe" INTERNAL_NAME="GOOPOS.exe" LEGAL_COPYRIGHT="Copyright © 2013" VERDATEHI="0x0" VERDATELO="0x0" VERFILEOS="0x4" VERFILETYPE="0x1" MODULE_TYPE="WIN32" PE_CHECKSUM="0x0" LINKER_VERSION="0x0" UPTO_BIN_FILE_VERSION="1.0.0.0" UPTO_BIN_PRODUCT_VERSION="1.0.0.0" LINK_DATE="07/17/2015 20:05:14" UPTO_LINK_DATE="07/17/2015 20:05:14" VER_LANGUAGE="Language Neutral [0x0]" EXE_WRAPPER="0x0" />
<MATCHING_FILE NAME="Microsoft.PointOfService.ControlBase.dll" SIZE="478456" CHECKSUM="0x1570016A" BIN_FILE_VERSION="1.14.1.0" BIN_PRODUCT_VERSION="1.14.1.0" PRODUCT_VERSION="1.14.1.0" FILE_DESCRIPTION="Microsoft.PointOfService.ControlBase" COMPANY_NAME="Microsoft Corporation" PRODUCT_NAME="POS for .NET 1.14" FILE_VERSION="1.14.1.0" ORIGINAL_FILENAME="Microsoft.PointOfService.ControlBase.dll" INTERNAL_NAME="Microsoft.PointOfService.ControlBase.dll" LEGAL_COPYRIGHT="Copyright (c) Microsoft Corporation. All rights reserved." VERDATEHI="0x0" VERDATELO="0x0" VERFILEOS="0x4" VERFILETYPE="0x2" MODULE_TYPE="WIN32" PE_CHECKSUM="0x7EAEF" LINKER_VERSION="0x0" UPTO_BIN_FILE_VERSION="1.14.1.0" UPTO_BIN_PRODUCT_VERSION="1.14.1.0" LINK_DATE="03/06/2014 21:31:15" UPTO_LINK_DATE="03/06/2014 21:31:15" VER_LANGUAGE="Language Neutral [0x0]" EXE_WRAPPER="0x0" />
<MATCHING_FILE NAME="Microsoft.PointOfService.dll" SIZE="513272" CHECKSUM="0xAEE452E6" BIN_FILE_VERSION="1.14.1.0" BIN_PRODUCT_VERSION="1.14.1.0" PRODUCT_VERSION="1.14.1.0" FILE_DESCRIPTION="Microsoft.PointOfService" COMPANY_NAME="Microsoft Corporation" PRODUCT_NAME="POS for .NET 1.14" FILE_VERSION="1.14.1.0" ORIGINAL_FILENAME="Microsoft.PointOfService.dll" INTERNAL_NAME="Microsoft.PointOfService.dll" LEGAL_COPYRIGHT="Copyright (c) Microsoft Corporation. All rights reserved." VERDATEHI="0x0" VERDATELO="0x0" VERFILEOS="0x4" VERFILETYPE="0x2" MODULE_TYPE="WIN32" PE_CHECKSUM="0x8CE41" LINKER_VERSION="0x0" UPTO_BIN_FILE_VERSION="1.14.1.0" UPTO_BIN_PRODUCT_VERSION="1.14.1.0" LINK_DATE="03/06/2014 21:31:12" UPTO_LINK_DATE="03/06/2014 21:31:12" VER_LANGUAGE="Language Neutral [0x0]" EXE_WRAPPER="0x0" />
<MATCHING_FILE NAME="System.Xaml.dll" SIZE="638888" CHECKSUM="0xA8E31324" BIN_FILE_VERSION="4.0.30319.17929" BIN_PRODUCT_VERSION="4.0.30319.17929" PRODUCT_VERSION="4.0.30319.17929" FILE_DESCRIPTION="System.Xaml.dll" COMPANY_NAME="Microsoft Corporation" PRODUCT_NAME="Microsoft® .NET Framework" FILE_VERSION="4.0.30319.17929 built by: FX45RTMREL" ORIGINAL_FILENAME="System.Xaml.dll" INTERNAL_NAME="System.Xaml.dll" LEGAL_COPYRIGHT="© Microsoft Corporation. All rights reserved." VERDATEHI="0x0" VERDATELO="0x0" VERFILEOS="0x4" VERFILETYPE="0x2" MODULE_TYPE="WIN32" PE_CHECKSUM="0xAA09E" LINKER_VERSION="0x0" UPTO_BIN_FILE_VERSION="4.0.30319.17929" UPTO_BIN_PRODUCT_VERSION="4.0.30319.17929" LINK_DATE="07/09/2012 06:24:11" UPTO_LINK_DATE="07/09/2012 06:24:11" VER_LANGUAGE="English (United States) [0x409]" EXE_WRAPPER="0x0" />
</EXE>
<EXE NAME="kernel32.dll" FILTER="CMI_FILTER_THISFILEONLY">
<MATCHING_FILE NAME="kernel32.dll" SIZE="868352" CHECKSUM="0x6B2E52BD" BIN_FILE_VERSION="6.1.7601.18409" BIN_PRODUCT_VERSION="6.1.7601.18409" PRODUCT_VERSION="6.1.7601.18015" FILE_DESCRIPTION="Windows NT BASE API Client DLL" COMPANY_NAME="Microsoft Corporation" PRODUCT_NAME="Microsoft® Windows® Operating System" FILE_VERSION="6.1.7601.18015 (win7sp1_gdr.121129-1432)" ORIGINAL_FILENAME="kernel32" INTERNAL_NAME="kernel32" LEGAL_COPYRIGHT="© Microsoft Corporation. All rights reserved." VERDATEHI="0x0" VERDATELO="0x0" VERFILEOS="0x40004" VERFILETYPE="0x2" MODULE_TYPE="WIN32" PE_CHECKSUM="0xE111D" LINKER_VERSION="0x60001" UPTO_BIN_FILE_VERSION="6.1.7601.18409" UPTO_BIN_PRODUCT_VERSION="6.1.7601.18409" LINK_DATE="03/04/2014 09:16:37" UPTO_LINK_DATE="03/04/2014 09:16:37" EXPORT_NAME="KERNEL32.dll" VER_LANGUAGE="English (United States) [0x409]" EXE_WRAPPER="0x0" FILE_ID="000083343001edfa431e3e441c012621f3e2bab3980c" PROGRAM_ID="0000f519feec486de87ed73cb92d3cac802400000000" />
</EXE>
</DATABASE>
Kindly advise..
Thanks,
Jassim[^]
Technology News @ www.JassimRahma.com
|
|
|
|
|
There really isn't anything we can do to help here: there are just too many variables.
So start by looking for differences between the PC where it works - your development PC - and teh PC where it doesn't. Look at the OS, the size (32 bit / 64 bit), the .NET versions installed, the datafiles your app uses, databases, the disk space, anything which is different. If you can't find anything there that looks significant, then start by adding logging info to your app and work out how far it gets before it crashes.
Then, narrow the area down with more logging, and start using try...catch blocks to try and find out what the exception (if any) is.
There isn't anything we can do from this end: you need to gather information and start thinking about your code - which we can't do because we have no access to it!
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
There is a good change you didn't deploy one or more .DLL's those referenced .DLL's depends on. With the information you provided there isn't enough information to tell which .DLL(s) are missing dependencies, if any.
I suggest you go down the list of the assemblies you references and get the documentation on each library to see if you have to do something special on the client machine to deploy that library.
|
|
|
|
|
Hi,
I want to get google place predictions with latitude, longitude and address based on Textbox entry in c# server side.
I tried in client side using
var places = new google.maps.places.Autocomplete(document.getElementById('txtPlaces'));
But i want to achieve in Server side C#.
How to achieve this.
If anybody knows, please reply me.
Thanks in advance.
|
|
|
|
|
I haven't tried it, but you might want to start looking at GMaps.Net[^]
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
I need a windows phone 7.1 code that can track’ location and the distance it has moved from where I am and also the speed it was on to reach where its current location .
|
|
|
|
|
So when do you get started writing that?
|
|
|
|
|
i just need the basics of GPS speedometer and distance tracker code for a car.
|
|
|
|
|
Sounds like you want someone to write it for you - wrong site. There are many sites where you can buy that service. This is not one of them.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Hi, Im working in C# and trying to get string[] to int when I get an error:
My code:
string htmlCodee = Client.DownloadString("http://tf2casino.cf/prices/key.txt");
string[] htmlCode = htmlCodee.Replace("\r", "").Split('\n');
int low = Convert.ToInt32(htmlCode[1]);
My error:
ERROR: System.FormatException: De indeling van de
invoertekenreeks is onjuist.
bij System.Number.StringToNumber(String str, NumberStyles options, NumberBuff
er& number, NumberFormatInfo info, Boolean parseDecimal)
bij System.Number.ParseInt32(String s, NumberStyles style, NumberFormatInfo i
nfo)
bij System.Convert.ToInt32(String value)
bij SteamBot.SimpleUserHandler.PriceUpdate() in c:\Users\Gebruiker\Documents\
Bot\KeyBot\SteamBot\SimpleUserHandler.cs:regel 136
bij SteamBot.SimpleUserHandler.OnLoginCompleted() in c:\Users\Gebruiker\Docum
ents\Bot\KeyBot\SteamBot\SimpleUserHandler.cs:regel 107
bij SteamBot.Bot.<handlesteammessage>b__5(LoginKeyCallback callback) in c:\Us
ers\Gebruiker\Documents\Bot\KeyBot\SteamBot\Bot.cs:regel 436
bij SteamKit2.CallbackMsgExtensions.Handle[T](ICallbackMsg msg, Action`1 hand
ler)
bij SteamBot.Bot.HandleSteamMessage(ICallbackMsg msg) in c:\Users\Gebruiker\D
ocuments\Bot\KeyBot\SteamBot\Bot.cs:regel 416
bij SteamBot.Bot.BackgroundWorkerOnDoWork(Object sender, DoWorkEventArgs doWo
rkEventArgs) in c:\Users\Gebruiker\Documents\Bot\KeyBot\SteamBot\Bot.cs:regel 89
6
(Sorry for random NL text between it)
-Greetings, Jonathan
|
|
|
|
|
Start by using the debugger and looking at the data you have downloaded from the file: what exactly does it contain?
Then look at the array content post-split: what is in the second array element, exactly?
The chances are that the data is not what you expect, and the "second line" does not contain just a number.
But we can't check that for you!
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
I saw the file, and i suppose you get these 2 strings:
"15.66"
"15.88"
Those strings hold double value, and you get exception because of that.
Greetings
|
|
|
|
|
Hi,
I have frmMain which is an MDI Container and (frmCustomer & frmOrders) which are MDI child
On frmMain I have panelHeader.
I want to hide panelHeader every time frmCustomer or frmOrders are shown and then show it back when MDI child is closed.
so what I want is if an MDI child is shown (MDI Child > 0) then panelHeader visibility to be false else it should be true.
How can I dot this please?
Thanks,
Jassim[^]
Technology News @ www.JassimRahma.com
|
|
|
|
|
Toggle the Visibility-property in the appropriate event.
That might mean having a window-focus event recounting how much of those windows are approrpriate (OfType<frmcustomer> and..) and update the status.
What have you tried?
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Ive create a method that will handle keydown event
it has a lot of "if" statment and it say i has a high complexity and its scores 33
is there way to decrease its complexity
actually the method is not finish
here is the code
private static void FlyouCommandEvent(object sender, KeyEventArgs e)
{
var fd = (FlyoutDialog)sender;
if ((e.KeyCode == Keys.A || (e.Alt && e.KeyCode == Keys.A)) && fd.CanExecuteCommand(Helpers.FlyoutCommandAbort))
{
fd.ExecuteCommand(Helpers.FlyoutCommandAbort);
}
else if (e.KeyCode == Keys.Escape && fd.CanExecuteCommand(Helpers.FlyoutCommandCancel))
{
fd.ExecuteCommand(Helpers.FlyoutCommandCancel);
}
else if ((e.KeyCode == Keys.I || (e.Alt && e.KeyCode == Keys.I)) && fd.CanExecuteCommand(Helpers.FlyoutCommandIgnore))
{
fd.ExecuteCommand(Helpers.FlyoutCommandIgnore);
}
else if ((e.KeyCode == Keys.N || (e.Alt && e.KeyCode == Keys.N)) && fd.CanExecuteCommand(Helpers.FlyoutCommandNo))
{
fd.ExecuteCommand(Helpers.FlyoutCommandNo);
}
else if ((e.KeyCode == Keys.N || (e.Alt && e.KeyCode == Keys.N)) && fd.CanExecuteCommand(Helpers.FlyoutCommandNone))
{
fd.ExecuteCommand(Helpers.FlyoutCommandNone);
}
else if (e.KeyCode == Keys.Enter && fd.CanExecuteCommand(Helpers.FlyoutCommandOK))
{
fd.ExecuteCommand(Helpers.FlyoutCommandOK);
}
else if ((e.KeyCode == Keys.R || (e.Alt && e.KeyCode == Keys.R)) && fd.CanExecuteCommand(Helpers.FlyoutCommandRetry))
{
fd.ExecuteCommand(Helpers.FlyoutCommandRetry);
}
else if ((e.KeyCode == Keys.Y || (e.Alt && e.KeyCode == Keys.Y)) && fd.CanExecuteCommand(Helpers.FlyoutCommandYes))
{
fd.ExecuteCommand(Helpers.FlyoutCommandYes);
}
}
any suggestion is highly appreciated
thank you
modified 17-Jul-15 4:47am.
|
|
|
|
|
there is switch....catch option is availabel as alternate option of if condition
|
|
|
|
|
Thank you so much, but i guess switch cant handle expressions. Correct if I am wrong.
|
|
|
|
|
There's a heck of a lot of code going on here, and it certainly appears as though you're violating SRP here. Rather than doing things like this, I would look to implement separate classes that do what you need to do - each class would then decide whether it was the one that handled the case. There's even a name for this, as a pattern; it's called the Chain Of Responsibility. So, you would end up with something like this:
public abstract class HandlerBase
{
private IHandler successor;
public void SetSuccessor(IHandler successor)
{
this.successor = handler;
}
public virtual void HandleRequest(KeyEventArgs e)
{
if (CanHandleRequest(e))
{
return;
}
if (successor != null)
{
successor.HandleRequest(e);
}
}
public abstract bool CanHandleRequest(KeyEventArgs e);
public abstract void HandleRequest(FlyoutDialog fd);
}
public class FlyoutAbort : HandlerBase
{
public virtual bool CanHandleRequest(KeyEventArgs e)
{
return (e.KeyCode == Keys.A || (e.Alt && e.KeyCode == Keys.A)) && fd.CanExecuteCommand(Helpers.FlyoutCommandAbort);
}
public abstract void HandleRequest(FlyoutDialog fd)
{
fd.ExecuteCommand(Helpers.FlyoutCommandAbort);
}
}
public class FlyoutCancel : HandlerBase
{
public virtual bool CanHandleRequest(KeyEventArgs e)
{
return e.KeyCode == Keys.Escape && fd.CanExecuteCommand(Helpers.FlyoutCommandCancel;
}
public abstract void HandleRequest(FlyoutDialog fd)
{
fd.ExecuteCommand(Helpers.FlyoutCommandCancel);
}
} Then, in your main class, you simply do this:
private FlyoutAbort flyoutAbort;
private FlyoutCancel flyoutCancel;
private void InitializeChain()
{
flyoutAbort = new FlyoutAbort();
flyoutCancel = new FlyoutCancel();
flyoutAbort.SetSuccessor(flyoutCancel);
} Finally, all you need to do to handle the request (if it can be handled that is), is call:
flyoutAbort.HandleRequest(e);
|
|
|
|
|
Nice one, let see what I can do. Thank you so much.
|
|
|
|
|