Sapien

Viewing 1 reply thread
  • Author
    Posts
    • #50160
      Participant
      Topics: 51
      Replies: 86
      Points: 12
      Rank: Member

      Hello, I'm new to Sapien and have a question that can probably be answered here...

      I have a list box I'm trying to keep updated with our locked out users, I want this listbox to be updated every 5 seconds or so.

      They have a prebuilt function for generating the contents of a list box, but i'm not sure where I would stick code to continuously update it...

      I have it generate the listbox on load as seen below, but where would i Stick some code to do like a

      do 
      {
        #$lockedlist is a checkedlistbox form object
        Load-ListBox $LockedList (Search-ADAccount -LockedOut) "name"
        start-sleep 5
      }
      while (1 -eq 1)
      

      Complete code below..

      
      $form1_Load={
      	#TODO: Initialize Form Controls here
      	
      	Load-ListBox $LockedList (Search-ADAccount -LockedOut) "name"
      	
      	
      }
      
      #region Control Helper Functions
      function Load-ListBox 
      {
      
      	Param (
      		[ValidateNotNull()]
      		[Parameter(Mandatory=$true)]
      		[System.Windows.Forms.ListBox]$ListBox,
      		[ValidateNotNull()]
      		[Parameter(Mandatory=$true)]
      		$Items,
      	    [Parameter(Mandatory=$false)]
      		[string]$DisplayMember,
      		[switch]$Append
      	)
      	
      	if(-not $Append)
      	{
      		$listBox.Items.Clear()	
      	}
      	
      	if($Items -is [System.Windows.Forms.ListBox+ObjectCollection] -or $Items -is [System.Collections.ICollection])
      	{
      		$listBox.Items.AddRange($Items)
      	}
      	elseif ($Items -is [System.Collections.IEnumerable])
      	{
      		$listBox.BeginUpdate()
      		foreach($obj in $Items)
      		{
      			$listBox.Items.Add($obj)
      		}
      		$listBox.EndUpdate()
      	}
      	else
      	{
      		$listBox.Items.Add($Items)	
      	}
      
      	$listBox.DisplayMember = $DisplayMember	
      }
      #endregion
      
    • #50164
      Participant
      Topics: 51
      Replies: 86
      Points: 12
      Rank: Member

      Got it by adding a timer to the form

      $form1_Load={
      	#TODO: Initialize Form Controls here
      	
      	Load-ListBox $LockedList (Search-ADAccount -LockedOut) "name"
      	# timer1
      	#
      	$timer1.Enabled = $True
      	$timer1.Interval = 3000
      	$timer1.add_Tick($timer1_Tick)
      }
      

      $timer1_Tick={
      #TODO: Place custom script here
      Load-ListBox $LockedList (Search-ADAccount -LockedOut) "name"
      }

Viewing 1 reply thread
  • The topic ‘Sapien’ is closed to new replies.