Sometimes, and as far as I have been able to determine after I have cancelled a build, the “Find in Files” function in Visual Studio (2010 and 2012) isn’t working. It wouldn’t search all the files in my solution.
According to the below, the solution is, amoun other, to press <Ctrl + Scroll lock>. This key combination however is the only one I’ve tried.


Quote
Hi all,

Thank you for your continued interest in this bug. We have been able to reproduce the issue intermittently in several versions of Visual Studio running on several versions of Windows and have identified the root cause as external to VS. The Windows team unfortunately did not have time to fix this for their current release, but we are working with them to hopefully have this bug fixed for a future version of Windows. At present, the workaround (as many of you noted) is to press Ctrl+Scroll Lock, Ctrl+Break, or the Break key alone.

Again, thanks for all of the details you provided about this bug. If you have any further questions or comments, please feel free to post again here; although this issue was closed quite a while ago, I'll make sure it stays on our radar.

Thanks, Brittany Behrens Program Manager, VS Platform - Editor
End Quote

Unfortunately I haven’t been able to find the link to this post.


As always, feel free to comment, or ask.


Did you know that
Event -= new EventHandler(yourEventHandler)
wouldn’t unsubscribe the event handler from the event. This means that the object that contains the event still holds a reference to the object containing the event handler and visa versa. And if you try to dispose one of the object, the GarbageCollector wouldn’t collect it. It will remain in memory until both object are disposed.

The way to resolve this is to make an instance of the delegate you want to subscribe to the event, and unsubscribe this instance from the event.

An example might be in order here:

public class Foo : IDisposable
{
    public event System.EventHandler AnEvent;

    private void RaiseEvent()
    {
        if (AnEvent != null)
        {
            AnEvent(this, new System.EventArgs());
        }
    }

    void IDisposable.Dispose()
    {
        AnEvent = null;
    }
}

public class Bar : IDisposable
{
    private System.EventHandler _eventHandler = null;
    public System.EventHandler EventHandler
    {
        get
        {
            //If no instance of _eventHandler exist, create a new one
            if (_eventHandler == null)
            {
                _eventHandler = new System.EventHandler(theEventHandler);
            }
            return _eventHandler;
        }
    }

    private Foo _foo;

    public Bar()
    {
        _foo = new Foo();
        _foo.AnEvent += EventHandler; //Subscribe to AnEvent
    }

    private void theEventHandler(object sender, System.EventArgs e)
    {
        //Do the handling stuff
    }

    void IDisposable.Dispose()
    {
        _foo.AnEvent -= EventHandler; //UnSubscribe from AnEvent
        _foo = null;
    }
}


Notice that I have created an instance of the event handler delegate in the

public EventHandler EventHandler


property.
This instance (_eventHandler) is the instance that I subscribe to the event

_foo.AnEvent += EventHandler;


and unsubscribe again in Dispose

 

_foo.AnEvent -= EventHandler;

 


As always, feel free to comment or ask.


InvalidOperationException: "Cross-thread operation not valid: Control '<name>' accessed from a thread other than the thread it was created on."

If you are getting this exception it means that your are trying to access a Control - running on the main thread of your application, say ThreadA - from another thread, ThreadB.

This other ThreadB could of-course be either a

System.Threading.Thread

 or a

System.ComponentModel.BackgroundWorker

or whatever.


The way to get around this, is by using invocation in the Control.


Here is a example if you don’t need a return value:

public void AddMessage(MessageType type, Message message)
{
    internalAddMessage(type, message);
}

private void internalAddMessage(MessageType type, Message message)
{
    if (this.InvokeRequired)
    {
        this.Invoke((MethodInvoker)delegate { internalAddMessage(type, message); });
        return;
    }
    //Do the 'Add Message' stuff you want to do
}

or if you need a return value from the Invoked method:

 

private DialogResult internalShowDialog()
{
    if (this.InvokeRequired)
    {
        Func<DialogResult> func = new Func<DialogResult>(internalShowDialog);
        return (DialogResult)this.Invoke(func);
    }
    else
    {
        return this.ShowDialog();
    }
}

Now, what is this? ...

Published 11/14/2012 by Christian
Tags:

Hi
Well... Why this blog? OK - to make a short story looong.
Way back when, when the air was clean and sex was du... OK maybe not that looong.
Anyhow - perhaps some background first.
I’m a software engineer, and I have been developing C/C++/C# embedded and Windows software for more than 11 years now. Currently I am working with .Net 4.5 Windows applications ... and software development is what this blog is about.


I once attended a seminar, with a very renowned software guru.  Unfortunately I have forgotten his name in the meantime. But I do remember some of the things he thought.
One of them, and one I took to heart at once, was to, during the development of software, keep kind of like a journal. And in that journal, keep track of what you are doing. Which problems you are solving. Which good ideas you get. Nice ways to get around, or perhaps straight though, complicated challenges.
Once every now and then, say every fought night, read through the journal, so you'll remember what you have written about. In that way you will never have to solve the same problems over and over again. You will never have to come up with the same brilliant ideas over and over again. And you will never have to use pressures time figuring out how to tagle the same complicated challenges over and over again.
As mentioned before, this was way back when... or perhaps just back when there were no clouds out there in cyberspace. So I started out using... you know... pen and paper. Unfortunately this first journal got lots somehow while switching jobs - and I didn't have a backup (in case you missed it, that was a joke. Kind of like the one that goes "I haven't lost my mind. It's on back somewhere"). Anyway then I started using a Word document. All well and good. Migrated this to a Google Docs (now Google Drive), and now I'm pretty sure that I'll never loose it again.
But lately I've been thinking that perhaps other people could benefit from my experience, and then I decided to start this blog.
So back to the starting point, and my first question: Why this blog? And that's it. To be able to keep track of my journal, and in the hopes that you folks can benefit from my experience.
Hope you enjoy it.

Best regards
Christian