Author Topic: Exit (by pressing Esc) program that has no use input?  (Read 9410 times)

0 Members and 1 Guest are viewing this topic.

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Exit (by pressing Esc) program that has no use input?
« Reply #15 on: August 14, 2007, 11:17:36 AM »
At first I set the limit to 30.  Then I didn't set a limit, but let the user 'escape' out of the command to end it.  My idea was that it would run at night, so that it could run without barring me from using my computer, but that didn't work either.  When I run the command, and then lock my computer (ctrl+alt+del, lock computer) it will only run for around 5 minutes then stop.  Also I can see it eating memory with 'task manager' open while the command is running, but it will run for a while when everything is open, and the computer isn't locked, but once it's locked it stops by itself.  Mystery to me.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Exit (by pressing Esc) program that has no use input?
« Reply #16 on: August 14, 2007, 06:24:03 PM »
Okay, so I see what the problem is, but I don't know how to fix it, but will do some research when I have time.  But in case someone knows how to fix it, here is the problem.

Once you run the program, it will run as long as Acad keeps the focus.  Once you select another program, then the program seems to quit running.  The way I tested this was to add a print to the command line on every 20,000 time it tested a string, and as soon as I picked another program with the mouse, it would stop printing to the command line, and the program would be not responsive within the task manager.  If anyone has any suggestions please let me know.

Thanks.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

Glenn R

  • Guest
Re: Exit (by pressing Esc) program that has no use input?
« Reply #17 on: August 14, 2007, 08:03:31 PM »
Eating memory huh? Strings are immutable in .NET remember.......

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Exit (by pressing Esc) program that has no use input?
« Reply #18 on: August 15, 2007, 12:23:19 AM »
Eating memory huh? Strings are immutable in .NET remember.......
Didn't remember.  Let me look into this.  Thanks Glenn.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Exit (by pressing Esc) program that has no use input?
« Reply #19 on: August 15, 2007, 01:16:57 AM »
It looks like the StringBuilder class is the way to go for this, so that memory won't go wild.  Hopefully I will have some time tomorrow at work to try it out.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

Glenn R

  • Guest
Re: Exit (by pressing Esc) program that has no use input?
« Reply #20 on: August 15, 2007, 01:54:53 AM »
Yep - StringBuilder is the way to go Tim.

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8718
  • AKA Daniel
Re: Exit (by pressing Esc) program that has no use input?
« Reply #21 on: August 15, 2007, 11:42:15 AM »
I wrote a simple version in C++ in hopes of running it while I was out today, but for some reason the OS updater rebooted my machine.
Anyway one of the drawbacks of using .NET in a case like this is your code has to go through all the managed wrapper mojo.
 If you reflect GetSystemVariable() you can see that  it uses ResbufToObject(), its quite a chunk of code with some memory pinning and marshalling.
 I am not surprised that your routine is a memory hog.

Regardless, you do realize that AutoCAD 2145 will probably be out before you crunch through 128^30 variants. But it is fun though  8-)

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Exit (by pressing Esc) program that has no use input?
« Reply #22 on: August 15, 2007, 11:53:15 AM »
Thanks for the info Daniel.

Regardless, you do realize that AutoCAD 2145 will probably be out before you crunch through 128^30 variants. But it is fun though  8-)
True.  Now I'm using this as a learning idea now, but hope it works and produces something useful.  :-)
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Exit (by pressing Esc) program that has no use input?
« Reply #23 on: August 15, 2007, 01:05:30 PM »
I can't get StringBuilder to work the way it looks (to me) it should work.  It looks like you can replace a character (char) at a specific spot with a new char, but it won't work.
Code: [Select]
return sbStr[Location - 1] = tempChar;
Returns error
Quote
Cannot implicityly convert type 'char' to 'System.Text.StringBuilder'

No matter what I try I can't seem to get this to work.  All the other parts seem to work.

Nevermind.  I have to place the new char before I could return the value of the string builder.
« Last Edit: August 15, 2007, 01:08:04 PM by T.Willey »
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Exit (by pressing Esc) program that has no use input?
« Reply #24 on: August 15, 2007, 01:43:29 PM »
It still loses focus though, and will not continue.  This will be my next test.  I don't want to have to add in code that puts the focus on the calling Acad window, but that may be the only way.

New code.
Code: [Select]
namespace Test
{
/// <summary>
/// Description of GetSystemVariablescs.
/// </summary>
public class GetSystemVariablescs
{

[DllImport("acad.exe", CallingConvention = CallingConvention.Cdecl, EntryPoint = "acedUsrBrk")]
private static extern int acedUsrBrk();

private StringBuilder UpStringLetters (StringBuilder sbStr, int Location) {
if (Location.Equals(0))
return sbStr.Insert(0, 'A');
else if (sbStr[Location - 1].Equals('Z')) {
sbStr[Location - 1] = 'A';
return UpStringLetters (sbStr, (Location - 1));
}
else if (sbStr.Length.Equals(1)) {
char tempChar = sbStr[0];
tempChar = ++tempChar;
sbStr[0] = tempChar;
return sbStr;
}
else {
char tempChar = sbStr[Location - 1];
tempChar = ++tempChar;
sbStr[Location - 1] = tempChar;
return sbStr;
}
}

[CommandMethod("PrintVariables")]
public void Main () {
PromptResult pr = AcadApp.DocumentManager.MdiActiveDocument.Editor.GetString("\n Enter value to start at: ");
string TestString = pr.StringResult;
if (string.Compare(TestString, string.Empty).Equals(0))
return;
StringBuilder sbString = new StringBuilder(TestString.ToUpper(), 30);
object VarValue;
int i = 0;
using (StreamWriter sw = new StreamWriter("C:/MyCustom/VariableList-CSharp.txt", true)) {
while (acedUsrBrk().Equals(0)) {
try {
VarValue = AcadApp.GetSystemVariable(sbString.ToString());
if (VarValue != null) {
sw.WriteLine(sbString + "," + VarValue.ToString());
sw.Flush();
}
}
catch {}
try {
VarValue = AcadApp.GetSystemVariable(sbString.Insert(0,'_').ToString());
if (VarValue != null) {
sw.WriteLine(sbString + "," + VarValue.ToString());
sw.Flush();
}
}
catch {}
if (sbString[0].Equals('_'))
    sbString.Remove(0,1);
sbString = UpStringLetters (sbString, sbString.Length);
++i;
if (i > 20000) {
AcadApp.DocumentManager.MdiActiveDocument.Editor.WriteMessage("\n Test string = " + sbString.ToString());
//System.GC.Collect();
i = 0;
}
}
sw.WriteLine("** Canceled at [ " + sbString + " ]");
}
AcadApp.DocumentManager.MdiActiveDocument.Editor.WriteMessage(sbString.ToString());
}
}
}
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.