Click here to Skip to main content
15,890,557 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi Experts,
I'm building a long list of Visual Studio projects using msbuild. And while hiding the msbuild output, displaying a status and an animation based upon some characters is displayed while msbuild doing its job. Here my script to build using msbuild and display wait animation (You will surely like this...):

$anim=@("|","/","-","\","|") # Animation sequence characters<br />
$ReturnCode = @{}<br />
$BuildStatus="Building $(ProjectName)" <br />
<br />
$CursorTop=[Console]::CursorTop #// Cursor position on Y axis<br />
$CursorLeft=$BuildStatus.Length #// Cursor position on X axis <br />
Write-Host $BuildStatus -ForegroundColor Cyan<br />
<br />
#// starting the MsBuild job in background.<br />
<br />
$MsbJob = [PowerShell]::Create().AddScript(<br />
{<br />
  param($MsbArgs, $Result)<br />
  & msbuild $MsbArgs | Out-Null<br />
  $Result.Value = $LASTEXITCODE<br />
}<br />
).AddArgument($MsbArgs).AddArgument($ReturnCode)<br />
<br />
$async = $MsbJob.BeginInvoke() #// start executing the job.<br />
<br />
#// While above script block is doing its job in background, display status and animation in console window.<br />
<br />
while (!$async.IsCompleted)<br />
{<br />
    foreach ($item in $anim) #// looping on array containing characters to form animation<br />
    {<br />
<br />
       [Console]::SetCursorPosition($CursorLeft + 5,$CursorTop) #//setting position for cursor<br />
       Write-Host $item -ForegroundColor Yellow <br />
       Start-Sleep -m 50<br />
    }<br />
}<br />
<br />
$MsbJob.EndInvoke($async)<br />
<br />


most of the time, it works as expected i.e. showing the status like:

Building MyProject (Animating characters)..

but suddenly, it becomes like this:
http://img89.imageshack.us/img89/7650/4fh.png[^]

Only Discovered Solution: I was able to correct this is to increase the Screen Buffer Size of Console (Console Properties --> Layout: Screen Buffer Size) to 1024. In addition, I also increased Window Size to fill out the monitor and it didn't break like that.

Is my assessment about Screen Buffer is correct? or anything else is breaking up? If Yes, do I have to increase the screen buffer size pragmatically i.e. from inside my .psm1 script.?

Any help would be really appreciated.
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900