Τετάρτη 2 Μαρτίου 2016

Νήματα και Γεγονότα μαζί!

Θέλουν ακόμα δουλειά τα Γεγονότα, για να δουλεύουν σε όλες τις περιπτώσεις. Να ένα πρόγραμμα με εντολές στα αγγλικά, με νήματα και με γγονότα.



Event OnSpaceBar {
      Read t, a$, b
}
Class Inform1 {
Private:
      total, complete
Public:
      Event AddOne { }
      Event Print {
            Read what$
      }
      Function Any {
                  Read a$
                      .total++
                     Print a$
            }    
      Function AddNow {
            .complete++
      }
      Module Init {
           Event .Print new .Any()
           Event .AddOne new .AddNow()
      }
      Module PrintHelp {
            Call Event .Print
      }
      Module AddHelp {
            Call Event .AddOne
      }
      Module TotalPrint {
            Print "Total Lines:", .total
            Print "Complete Works:", .complete
      }
}
Global Group Inform=Inform1()
\\ fix references when we have an instance
Inform.init
Function OnSpaceHandler {
      Read thr, t$, kk
      Thread thr execute data t$, kk
      \\ we need the global here
      Inform.PrintHelp "ok"
}
Event OnSpaceBar New OnSpaceHandler()


Thread {
      Static a$, payload, t
      If t=0 Then {
            Inform.PrintHelp "no job......yet"
            If Not Empty Then {
                  Event OnSpaceBar Hold
                  Read a$, payload
                  t=payload
            }
       } Else {
             Inform.PrintHelp format$("working {0:2}%",(payload-t)/payload*100)
             t--
             If t<1 Then Event OnSpaceBar Release : Inform.AddHelp
       }      
} As theThread Interval 50

Main.Task 50 {
      select case inkey$
      case ""
            Inform.PrintHelp "wait...."
      case " "
            Call Event OnSpaceBar, theThread, "hello", 30
      else
            break
      end select
}
Threads Erase
Inform.TotalPrint

Δεν υπάρχουν σχόλια:

Δημοσίευση σχολίου

You can feel free to write any suggestion, or idea on the subject.