среда, 24 августа 2011 г.

MessageBox display called from a separate thread

It is modal only to the windows you created in the same thread.  None, I'm sure in your case.  Just use Control.Invole() to make it modal to the UI thread.  For example:

  public partial class Form1 : Form {
    public Form1() {
      InitializeComponent();
    }
    private delegate DialogResult MessageBoxDelegate(string msg, string title, MessageBoxButtons buttons, MessageBoxIcon icon);

    private void button1_Click(object sender, EventArgs e) {
      backgroundWorker1.RunWorkerAsync();
    }
    private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e) {
      this.Invoke(new MessageBoxDelegate(ShowMessage), "waz here", "nobugz", MessageBoxButtons.OK, MessageBoxIcon.Information);
    }
    private DialogResult ShowMessage(string msg, string title, MessageBoxButtons buttons, MessageBoxIcon icon) {
      return MessageBox.Show(this, msg, title, buttons, icon);
    }
  }

понедельник, 22 августа 2011 г.

Get Application Directory [C#]


Following examples show how to get application or assembly folder.

Directory of windows forms application (.exe)

Class Application in System.Window­s.Forms namespace has static property ExecutablePath. It contains path of the .exe file (that started the application) including the executable file name. To get only the folder part of the path, use static method GetDirectoryName of Path class.
[C#]
using System.IO;
using System.Windows.Forms;

string appPath = Path.GetDirectoryName(Application.ExecutablePath);

Directory of any loaded assembly (.exe or .dll)

First get reference to the assembly. You can use static methods of Assembly class. To get assembly of currently executing code use method Assembly.GetE­xecutingAssem­bly. To get assembly in which the specified class is defined use method Assembly.GetAs­sembly (with the specified class type as a paramater). The assembly must be loaded. Next get assembly file path using Assembly.CodeBase property.
[C#]
using System.IO;
using System.Reflection;

string path = Path.GetDirectoryName(
                     Assembly.GetAssembly(typeof(MyClass)).CodeBase);


See also

вторник, 16 августа 2011 г.

Rollback or Undo a ChangeSet in TFS 2010


TFS 2010 provides you the ability to Rollback or Undo a ChangeSet from TFS Product itself. You can also see it as a new pending change type as Rollback (new change type in the history) inside Team Explorer. 
This feature was earlier available in TFS 2008 as part of TFS Power Tools only, where you have to Rollback the Change Set using tfpt.exe. Here in TFS 2010 implementation you have to use the command-line application tf.exe to actually perform the rollback information.  More information about the tool is available here in the MSDN Library:  http://msdn.microsoft.com/en-us/library/dd380776(VS.100).aspx
The syntax is:
tf rollback /changeset:changesetfrom~changesetto [itemspec] [/recursive]
            [/lock:none|checkin|checkout] [/version:versionspec]
            [/keepmergehistory] [/noprompt] [/login:username,[password]]
tf rollback /toversion:versionspec itemspec [/recursive]
            [/lock:none|checkin|checkout] [/version:versionspec]
            [/keepmergehistory] [/noprompt] [/login:username,[password]]
 
Here, I am performing a Rollback of ChangeSet Number 22 which contains Form1.cs file.
 
Just do a check-in, your Rollback of ChangeSet will be done.