Small Basic – Synchronous and Asynchronous Type Operations


The challenge of this month has Multitasking Challenge.  In Small Basic, there are two types of operations.  One is synchronous type, the other is asynchronous type.  Most of operations are synchronous type that wait the operations done before starting the next step.  But some operations are asynchronous type that don’t wait the operations done.

Asynchronous Type Operations

Following operations are asynchronous type:

  • Shape.Animation()
  • Sound.Play()
  • Sound.PlayBellRing()
  • Sound.PlayChime()
  • Sound.PlayChimes()
  • Sound.PlayClick()

Synchronous Type Operations

Other operations than listed above are synchronous type.  Especially, following operations may need much time.

  • File.ReadContents()
  • Flickr.GetRandomPicture()
  • ImageList.LoadImage()
  • Network.GetWebPageContents()
  • Sound.PlayMusic()
  • Turtle.Move()

If you want to do something while running synchronous type operations, you should use events such as timer, mouse, keyboard or controls events.  On the other side, be careful to use these slow asynchronous type operations in an event handler subroutine.  The next event will occur while running the last event handler.

Comments (4)

  1. Yvan Leduc says:

    Very interesting article, like always 🙂
    What I want most in the world, is that programmers of Small Basic, those who have designed this program, they can improve the command :
    ‘ ‘ sound.playmusic ‘ ‘

    in order to put it in the Asynchronous category.
    Just because, you remember when i tried to make a slideshow in SBasic with music in the background, the music could’nt simply not follow the slides change images.
    In many cases, soundplay.music should be in the Asynchrome category, so a few video games made in Small Basic would gain to.
    Hoping that version 1.3 of SB can do this improve 🙂

    1. litdev says:

      Try something like:

      LDCall.CallComplete = OnCallComplete
      result = LDCall.CallAsync(“”,””,””,”DoWork”,””)
      TextWindow.WriteLine(result)
      For i = 1 To 100 ‘Just to show it is Async
      TextWindow.WriteLine(i)
      Program.Delay(100)
      EndFor

      Sub DoWork
      Sound.PlayMusic(“O5 C8 C8 G8 G8 A8 A8 G4 F8 F8 E8 E8 D8 D8 C4″)
      EndSub

      Sub OnCallComplete
      TextWindow.WriteLine(LDCall.LastCall+” Completed”)
      EndSub

  2. YLed says:

    @litdev
    yes, Great !! it works !! asynchronous music with images
    here a preview of a test slides show with music
    ‘ program YLed
    ‘ Sept 15th 2016
    ‘ slide show with music asynchronous
    ‘ program no: SGZ504

    1. Thank you litdev for your challenge and a simple sample code of LDCall.CallAsync().
      Thank you Yvan Leduc for sharing your program SGZ504 and also PMJ581 in https://social.msdn.microsoft.com/Forums/en-US/3f0eea43-7703-4cf8-91ca-aefeaf916880/slideshow-with-2-songs-fr-elise-followed-by-andantino-of-carulli-final-version?forum=smallbasic .

Skip to main content