multi threading

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • notregister

    multi threading

    my program have as many as 8 threads running at a same time. can different
    threads open a same file at the same time? let say thread1 open a file
    abc.txt at the same time with thread 2, both doing at different operation...
  • Michael C#

    #2
    Re: multi threading

    How big is the file and what operations are you doing on it? The reason I
    ask is, if it's a small file, would it make sense to read it all into memory
    and work with it? Are all threads just reading? Or are some trying to
    write to the file?

    Thanks,
    Michael C#

    "notregiste r" <notregister@di scussions.micro soft.com> wrote in message
    news:270E09FE-F9D9-49A7-8352-4B19C4261689@mi crosoft.com...[color=blue]
    > my program have as many as 8 threads running at a same time. can different
    > threads open a same file at the same time? let say thread1 open a file
    > abc.txt at the same time with thread 2, both doing at different
    > operation...[/color]


    Comment

    • notregister

      #3
      Re: multi threading

      Hi,

      the file is not very big, around 2kbytes, it is a .PRN file(printing). i am
      send this file to 2 different printers using threads. The reason i am doing
      this, is to find out whether threading allow me to print at different
      printers at the same time. Do u have other alternatives?

      Thanks
      youyi

      "Michael C#" wrote:
      [color=blue]
      > How big is the file and what operations are you doing on it? The reason I
      > ask is, if it's a small file, would it make sense to read it all into memory
      > and work with it? Are all threads just reading? Or are some trying to
      > write to the file?
      >
      > Thanks,
      > Michael C#
      >
      > "notregiste r" <notregister@di scussions.micro soft.com> wrote in message
      > news:270E09FE-F9D9-49A7-8352-4B19C4261689@mi crosoft.com...[color=green]
      > > my program have as many as 8 threads running at a same time. can different
      > > threads open a same file at the same time? let say thread1 open a file
      > > abc.txt at the same time with thread 2, both doing at different
      > > operation...[/color]
      >
      >
      >[/color]

      Comment

      • Cor Ligthert

        #4
        Re: multi threading

        NotRegister,

        There is no difference when you use 8 programs or 8 threads for reading the
        same file.

        All options as with the method that you use to read the file are the same.

        I hope this helps?

        Cor


        Comment

        • notregister

          #5
          Re: multi threading

          thanks, may i ask if i got problem regarding printing in windows, which forum
          should i go? i been trying to find a solution for my program for many days
          but still no suitable answer.

          For you information...
          1) I am design a vb.net program
          2)supposed to send a single file to 8 different printers to print at the
          same time

          I am have been using threads, to divide the task to the 8 printers. I have
          tried using printdocument, printDialog, process, but the main point i want to
          emphasize is that this program is to test printers that have not gone to the
          market, i will prefer if i am able to send a print job to the printers
          without installing any printer drivers in advance.

          i read many article which allow user to send RAW data directly to printer,
          what does it mean? does it mean i do not requred drivers? pls help me to
          clariy..

          Thanks
          youyi

          "Cor Ligthert" wrote:
          [color=blue]
          > NotRegister,
          >
          > There is no difference when you use 8 programs or 8 threads for reading the
          > same file.
          >
          > All options as with the method that you use to read the file are the same.
          >
          > I hope this helps?
          >
          > Cor
          >
          >
          >[/color]

          Comment

          • Cor Ligthert

            #6
            Re: multi threading

            Youyi,

            I have seen both parts of your question. In the multithreading part I see no
            problems. In the printing without drives have I thought it seen that Ken
            wrote to you that it is impossible.

            Mostly when there comes than no other answer, than nobody active in this
            newsgroups know an answer.

            However your question is difficult. You can print over the network however
            than you print to a spool or you can print to a parallel port (for mostly
            old printers as well serial ports) however than you can only connect one
            printer.

            So I think at least you have to tell more where those simultanisly 8
            printers are connected too.

            Not that I than have direct an answer.

            Cor



            Comment

            • Guest's Avatar

              #7
              Re: multi threading

              Youyi,

              I have seen both parts of your question. In the multithreading part I see no
              problems. In the printing without drives have I thought it seen that Ken
              wrote to you that it is impossible.

              Mostly when there comes than no other answer, than nobody active in this
              newsgroups know an answer.

              However your question is difficult. You can print over the network however
              than you print to a spool or you can print to a parallel port (for mostly
              old printers as well serial ports) however than you can only connect one
              printer.

              So I think at least you have to tell more where those simultanisly 8
              printers are connected too.

              Not that I than have direct an answer.

              Cor


              Comment

              • Herfried K. Wagner [MVP]

                #8
                Re: multi threading

                "notregiste r" <notregister@di scussions.micro soft.com> schrieb:[color=blue]
                > my program have as many as 8 threads running at a same time. can different
                > threads open a same file at the same time? let say thread1 open a file
                > abc.txt at the same time with thread 2, both doing at different
                > operation...[/color]

                Yes, that should work, at least when you open the files for reading. But
                what is the advantage of reading the same file more than one time at the
                same time?

                --
                M S Herfried K. Wagner
                M V P <URL:http://dotnet.mvps.org/>
                V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

                Comment

                • notregister

                  #9
                  Re: multi threading

                  Hi,

                  The program i designed have 3 option, usb printer,network printer and
                  parallel port printers. As for parallel port printers, i have successful
                  print with 8 printers with a physical electronics print switch. that is
                  connected to an PC. If it was the case of usb printers,it will be connected
                  to a usb hub, and finally if it is through a network, they will be connected
                  to the main PC through LAN.

                  As for the usb connection and network printing, i have been trying many type
                  of techniques like threading and processstartinf o() to help me, but to no
                  valid...
                  i try using windows API, but most of them refer to VB6, and they mostly use
                  default printing, i do not think changing default printers in different
                  threads will work, or does it work? not too sure...

                  Thanks for all your advices, i appreciated all ur helps, pls let know also
                  if there any other suitable platform to ask this type of question, because
                  personally i feel this is 50% VB.net question and 50% windows question, it
                  might not be enough to solve this with vb.net knowledge alone...

                  regards
                  YouYi

                  "Cor Ligthert" wrote:
                  [color=blue]
                  > Youyi,
                  >
                  > I have seen both parts of your question. In the multithreading part I see no
                  > problems. In the printing without drives have I thought it seen that Ken
                  > wrote to you that it is impossible.
                  >
                  > Mostly when there comes than no other answer, than nobody active in this
                  > newsgroups know an answer.
                  >
                  > However your question is difficult. You can print over the network however
                  > than you print to a spool or you can print to a parallel port (for mostly
                  > old printers as well serial ports) however than you can only connect one
                  > printer.
                  >
                  > So I think at least you have to tell more where those simultanisly 8
                  > printers are connected too.
                  >
                  > Not that I than have direct an answer.
                  >
                  > Cor
                  >
                  >
                  >
                  >[/color]

                  Comment

                  • Cor Ligthert

                    #10
                    Re: multi threading

                    Notregister,

                    What is the reason that when you can do it withouth multithreading, that you
                    cannot do it with multithreading.

                    When you can do it like this
                    do while notReady
                    subprint1
                    subprint2
                    subprint 3
                    etc
                    loop
                    sub print1
                    do while not Ready
                    print row
                    end sub

                    You can do it as well like this (in the most simple format)
                    MyThread1 = New System.Threadin g.Thread(Addres sOf me.print1)
                    MyThread2 = New System.Threadin g.Thread(Addres sOf me.print2)
                    MyThread3 = New System.Threadin g.Thread(Addres sOf me.print3)
                    etc until 8

                    MyThread1.start
                    MyThread2.start
                    MyThread3.start
                    etc. until 8
                    sub print1
                    print the complete file
                    end sub
                    etc.until 8

                    Cor


                    Comment

                    • notregister

                      #11
                      Re: multi threading

                      Hi Cor,

                      for parallel prot ,i can do it without multi threading, because most of the
                      broadcast printing is handle by a parallel ports electronic switch. As for
                      the other 2 option, i tried using multi threading. in fact i was using ur
                      second option in my program, the trouble is the selection of printername for
                      each thread, though 8 similar printer are connected to the same PC, but they
                      do have different printername and i wand different threads to point at
                      different printer...

                      for each thread i tried to stated a different printer name,

                      Dim prSet As New Printersettings
                      prSet.Printerna me = "Epson Inkjet 2"

                      but somehow whenever i tried to print,it fail to print to each respective
                      printers, only default printer

                      regards
                      youyi



                      "Cor Ligthert" wrote:
                      [color=blue]
                      > Notregister,
                      >
                      > What is the reason that when you can do it withouth multithreading, that you
                      > cannot do it with multithreading.
                      >
                      > When you can do it like this
                      > do while notReady
                      > subprint1
                      > subprint2
                      > subprint 3
                      > etc
                      > loop
                      > sub print1
                      > do while not Ready
                      > print row
                      > end sub
                      >
                      > You can do it as well like this (in the most simple format)
                      > MyThread1 = New System.Threadin g.Thread(Addres sOf me.print1)
                      > MyThread2 = New System.Threadin g.Thread(Addres sOf me.print2)
                      > MyThread3 = New System.Threadin g.Thread(Addres sOf me.print3)
                      > etc until 8
                      >
                      > MyThread1.start
                      > MyThread2.start
                      > MyThread3.start
                      > etc. until 8
                      > sub print1
                      > print the complete file
                      > end sub
                      > etc.until 8
                      >
                      > Cor
                      >
                      >
                      >[/color]

                      Comment

                      • Michael C#

                        #12
                        Re: multi threading

                        If you're just reading in the file, and it's not too darn big, I would just
                        read the whole thing in one time and print it from memory using multiple
                        threads or a single thread, or whatever method you wish. I was concerned
                        you might be attempting to read and write to the same file simultaneously
                        using multiple threads, which would obviously cause problems...


                        "notregiste r" <notregister@di scussions.micro soft.com> wrote in message
                        news:879FF08B-18A3-47AC-B927-D16DBD4CAD24@mi crosoft.com...[color=blue]
                        > Hi,
                        >
                        > the file is not very big, around 2kbytes, it is a .PRN file(printing). i
                        > am
                        > send this file to 2 different printers using threads. The reason i am
                        > doing
                        > this, is to find out whether threading allow me to print at different
                        > printers at the same time. Do u have other alternatives?
                        >
                        > Thanks
                        > youyi
                        >
                        > "Michael C#" wrote:
                        >[color=green]
                        >> How big is the file and what operations are you doing on it? The reason
                        >> I
                        >> ask is, if it's a small file, would it make sense to read it all into
                        >> memory
                        >> and work with it? Are all threads just reading? Or are some trying to
                        >> write to the file?
                        >>
                        >> Thanks,
                        >> Michael C#
                        >>
                        >> "notregiste r" <notregister@di scussions.micro soft.com> wrote in message
                        >> news:270E09FE-F9D9-49A7-8352-4B19C4261689@mi crosoft.com...[color=darkred]
                        >> > my program have as many as 8 threads running at a same time. can
                        >> > different
                        >> > threads open a same file at the same time? let say thread1 open a file
                        >> > abc.txt at the same time with thread 2, both doing at different
                        >> > operation...[/color]
                        >>
                        >>
                        >>[/color][/color]


                        Comment

                        • notregister

                          #13
                          Re: multi threading

                          Thanks for ur reply, that would really solve half of my question, now i left
                          with the printer problem...like i wrote in my other post, i would like each
                          of my threads to print this same document to a different printers, bypassing
                          the driver if possible, which mean sending a printer-ready data directly to
                          the printers it self, the trouble is, setting printername within each
                          threads...i really do not know whether windows and vb.net can really allow
                          broadcast printing? is there any example on broadcast printing? thanks

                          regards
                          youyi

                          "Michael C#" wrote:
                          [color=blue]
                          > If you're just reading in the file, and it's not too darn big, I would just
                          > read the whole thing in one time and print it from memory using multiple
                          > threads or a single thread, or whatever method you wish. I was concerned
                          > you might be attempting to read and write to the same file simultaneously
                          > using multiple threads, which would obviously cause problems...
                          >
                          >
                          > "notregiste r" <notregister@di scussions.micro soft.com> wrote in message
                          > news:879FF08B-18A3-47AC-B927-D16DBD4CAD24@mi crosoft.com...[color=green]
                          > > Hi,
                          > >
                          > > the file is not very big, around 2kbytes, it is a .PRN file(printing). i
                          > > am
                          > > send this file to 2 different printers using threads. The reason i am
                          > > doing
                          > > this, is to find out whether threading allow me to print at different
                          > > printers at the same time. Do u have other alternatives?
                          > >
                          > > Thanks
                          > > youyi
                          > >
                          > > "Michael C#" wrote:
                          > >[color=darkred]
                          > >> How big is the file and what operations are you doing on it? The reason
                          > >> I
                          > >> ask is, if it's a small file, would it make sense to read it all into
                          > >> memory
                          > >> and work with it? Are all threads just reading? Or are some trying to
                          > >> write to the file?
                          > >>
                          > >> Thanks,
                          > >> Michael C#
                          > >>
                          > >> "notregiste r" <notregister@di scussions.micro soft.com> wrote in message
                          > >> news:270E09FE-F9D9-49A7-8352-4B19C4261689@mi crosoft.com...
                          > >> > my program have as many as 8 threads running at a same time. can
                          > >> > different
                          > >> > threads open a same file at the same time? let say thread1 open a file
                          > >> > abc.txt at the same time with thread 2, both doing at different
                          > >> > operation...
                          > >>
                          > >>
                          > >>[/color][/color]
                          >
                          >
                          >[/color]

                          Comment

                          • Michael C#

                            #14
                            Re: multi threading

                            Sorry I'm not familiar with printing by bypassing the printer drivers... At
                            least not since WFW 3.11 LOL...

                            Thanks

                            "notregiste r" <notregister@di scussions.micro soft.com> wrote in message
                            news:168E2020-188A-4954-8922-B5CB5998FC27@mi crosoft.com...[color=blue]
                            > Thanks for ur reply, that would really solve half of my question, now i
                            > left
                            > with the printer problem...like i wrote in my other post, i would like
                            > each
                            > of my threads to print this same document to a different printers,
                            > bypassing
                            > the driver if possible, which mean sending a printer-ready data directly
                            > to
                            > the printers it self, the trouble is, setting printername within each
                            > threads...i really do not know whether windows and vb.net can really allow
                            > broadcast printing? is there any example on broadcast printing? thanks
                            >
                            > regards
                            > youyi
                            >
                            > "Michael C#" wrote:
                            >[color=green]
                            >> If you're just reading in the file, and it's not too darn big, I would
                            >> just
                            >> read the whole thing in one time and print it from memory using multiple
                            >> threads or a single thread, or whatever method you wish. I was concerned
                            >> you might be attempting to read and write to the same file simultaneously
                            >> using multiple threads, which would obviously cause problems...
                            >>
                            >>
                            >> "notregiste r" <notregister@di scussions.micro soft.com> wrote in message
                            >> news:879FF08B-18A3-47AC-B927-D16DBD4CAD24@mi crosoft.com...[color=darkred]
                            >> > Hi,
                            >> >
                            >> > the file is not very big, around 2kbytes, it is a .PRN file(printing).
                            >> > i
                            >> > am
                            >> > send this file to 2 different printers using threads. The reason i am
                            >> > doing
                            >> > this, is to find out whether threading allow me to print at different
                            >> > printers at the same time. Do u have other alternatives?
                            >> >
                            >> > Thanks
                            >> > youyi
                            >> >
                            >> > "Michael C#" wrote:
                            >> >
                            >> >> How big is the file and what operations are you doing on it? The
                            >> >> reason
                            >> >> I
                            >> >> ask is, if it's a small file, would it make sense to read it all into
                            >> >> memory
                            >> >> and work with it? Are all threads just reading? Or are some trying
                            >> >> to
                            >> >> write to the file?
                            >> >>
                            >> >> Thanks,
                            >> >> Michael C#
                            >> >>
                            >> >> "notregiste r" <notregister@di scussions.micro soft.com> wrote in message
                            >> >> news:270E09FE-F9D9-49A7-8352-4B19C4261689@mi crosoft.com...
                            >> >> > my program have as many as 8 threads running at a same time. can
                            >> >> > different
                            >> >> > threads open a same file at the same time? let say thread1 open a
                            >> >> > file
                            >> >> > abc.txt at the same time with thread 2, both doing at different
                            >> >> > operation...
                            >> >>
                            >> >>
                            >> >>[/color]
                            >>
                            >>
                            >>[/color][/color]


                            Comment

                            Working...