Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 343
  • Last Modified:

VS C# Housekeeping

I was just cleaning up some class libraries I have developed for an external application and I realized it would nice if when the application fires up any of the class libraries if there was a hot key I could set to tell me which class library has fired and perhaps where in the class library the current code is running. Most these libraries has multiple sections and once you put the code down for a few months it is tough to remember where you were for each section. What is best practice for identifying which code is running but also where in the code you are?
0
rwheeler23
Asked:
rwheeler23
  • 2
  • 2
2 Solutions
 
käµfm³d 👽Commented:
Are you essentially trying to remove "dead code" (i.e. code that is never used)?
0
 
Jaime OlivaresSoftware ArchitectCommented:
If you use a tool like Resharper, it will tell you which classes and methods are being used or not.
0
 
rwheeler23Author Commented:
No, in my case there have been several class libraries created for the external applications. Many of the screens look very similar. Aside from putting text on the form I would prefer to embed a hot key or some other mechanism so I can get a message saying "This code is in ths.dll" when the hot key is hit.  This would aid in pinpointing which set of source code needs to be examined.

Example: program1.dll, program2.dll, program3.dll
Suppose the form I am currently viewing on the screen is located in program2.dll
I hit the hot key and a messagebox appears saying "You are in Program2".

In others words, can I create a hotkey that will executed within a class library regradless of where in the class library the user currently resides?
0
 
Jaime OlivaresSoftware ArchitectCommented:
There is not a one-to-one relationship between a code portion and a binary file. A single portion of code can be used simultaneously by more than one binary (either DLL or EXE).
In a similar way, the code-file to project-file relationship instead is one-to-many too.
However, for the second case, you can use the following tool to determine which projects a file belongs to:
http://www.codeproject.com/Articles/42811/Find-File-in-Solution
0
 
rwheeler23Author Commented:
In my first attempt at this, I added a key_down event to fire when CTRL-W is pressed. Unfortunately when I press and hold CTRL-W the message box does not appear. I want this key down event to be associated with the form.  What am I missing here?
 
public partial class frmBOAImportMainForm : DexUIForm
    {
        // Set references to the GL Account Screen and to the Vendor Screen and the transaction integration screens
        static frmGLAccounts GLAccountsForm;
        static frmVendors VendorsForm;
        static frmIntegratePayables IntegratePayables;
        [DllImport("user32.dll")]
        private static extern short GetAsyncKeyState(Keys vKey);

        public frmBOAImportMainForm()
        {
            InitializeComponent();
            this.KeyDown += new KeyEventHandler(frmBOAImportMainForm_KeyDown);
        }

        private void btnExit_Click(object sender, EventArgs e)
        {
            this.Hide();
            this.Dispose();
        }

        private void btnGLAccounts_Click(object sender, EventArgs e)
        {
            if (GLAccountsForm == null || GLAccountsForm.Created == false)
            {
                GLAccountsForm = new frmGLAccounts();
            }

            GLAccountsForm.Show();
            GLAccountsForm.Activate();
            GLAccountsForm.Focus();
        }

        private void btnVendors_Click(object sender, EventArgs e)
        {
            if (VendorsForm == null || VendorsForm.Created == false)
            {
                VendorsForm = new frmVendors();
            }

            VendorsForm.Show();
            VendorsForm.Activate();
            VendorsForm.Focus();
        }

        private void btnIntegrate_Click(object sender, EventArgs e)
        {
            if (IntegratePayables == null || IntegratePayables.Created == false)
            {
                IntegratePayables = new frmIntegratePayables();
            }

            IntegratePayables.Show();
            IntegratePayables.Activate();
            IntegratePayables.Focus();
        }

        private void frmBOAImportMainForm_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.Control && KeyIsDown(Keys.W))
            {
                Console.WriteLine("Ctrl+W");
                MessageBox.Show("Here I am lost again!");
            }
        }
        private bool KeyIsDown(Keys key)
        {
            return (GetAsyncKeyState(key) < 0);
        }
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now