Sapien

This topic contains 1 reply, has 1 voice, and was last updated by Profile photo of ertuu85 ertuu85 1 month, 2 weeks ago.

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #50160
    Profile photo of ertuu85
    ertuu85
    Participant

    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
    
    • This topic was modified 1 month, 2 weeks ago by Profile photo of ertuu85 ertuu85.
    #50164
    Profile photo of ertuu85
    ertuu85
    Participant

    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 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.