It appears that you haven't created your form yet. Is this the case?
Your command method should instantiate the form and then call ShowDialog and that is it really. Nothing else needed in your CommandMethod.
[CommandMethod("TestProgressMeter")]
public void CmdTestProgressMeter()
{
MyProgressForm form = new MyProgressForm();
form.ShowDialog();
}
Inside the form you might have a button that will start the process. Here I call it button1. Also on the form is a ProgressBar and it is called progressBar1.
private void button1_Click(object sender, EventArgs e)
{
var path = @"C:\MyPathToMyDWGFiles\";
DirectoryInfo d = new DirectoryInfo(path);
FileInfo[] Files = d.GetFiles("*.dwg");
progressBar1.Maximum = Files.Length - 1;
progressBar1.Minimum = 0;
foreach (FileInfo file in Files)
{
var fileName = Path.GetFileName(file.FullName);
string dwgFlpath = path + fileName;
using (Database db = new Database(false, true))
{
db.ReadDwgFile(dwgFlpath, FileOpenMode.OpenForReadAndAllShare, false, null);
using (Transaction tr = db.TransactionManager.StartTransaction())
{
BlockTable bt = tr.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable;
BlockTableRecord btr = tr.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;
using (Circle crcl = new Circle())
{
crcl.Center = new Point3d(1, 1, 0);
crcl.Radius = 2;
btr.AppendEntity(crcl);
tr.AddNewlyCreatedDBObject(crcl, true);
}
tr.Commit();
}
db.SaveAs(dwgFlpath, DwgVersion.AC1024);
}
progressBar1.Increment(1);
}
}
Note:
1) C# is not my first language, but you should be able to get the idea from the above example.
2) I have not tested your code. Only showing how to setup progresssBar1 and then increment using your foreach loop.
3) I am assuming that you've created your form and added a ProgressBar and a Button.
I hope that this helps.