Search Results

Search found 834 results on 34 pages for 'looping'.

Page 9/34 | < Previous Page | 5 6 7 8 9 10 11 12 13 14 15 16  | Next Page >

  • C#: Handling Notifications: inheritance, events, or delegates?

    - by James Michael Hare
    Often times as developers we have to design a class where we get notification when certain things happen. In older object-oriented code this would often be implemented by overriding methods -- with events, delegates, and interfaces, however, we have far more elegant options. So, when should you use each of these methods and what are their strengths and weaknesses? Now, for the purposes of this article when I say notification, I'm just talking about ways for a class to let a user know that something has occurred. This can be through any programmatic means such as inheritance, events, delegates, etc. So let's build some context. I'm sitting here thinking about a provider neutral messaging layer for the place I work, and I got to the point where I needed to design the message subscriber which will receive messages from the message bus. Basically, what we want is to be able to create a message listener and have it be called whenever a new message arrives. Now, back before the flood we would have done this via inheritance and an abstract class: 1:  2: // using inheritance - omitting argument null checks and halt logic 3: public abstract class MessageListener 4: { 5: private ISubscriber _subscriber; 6: private bool _isHalted = false; 7: private Thread _messageThread; 8:  9: // assign the subscriber and start the messaging loop 10: public MessageListener(ISubscriber subscriber) 11: { 12: _subscriber = subscriber; 13: _messageThread = new Thread(MessageLoop); 14: _messageThread.Start(); 15: } 16:  17: // user will override this to process their messages 18: protected abstract void OnMessageReceived(Message msg); 19:  20: // handle the looping in the thread 21: private void MessageLoop() 22: { 23: while(!_isHalted) 24: { 25: // as long as processing, wait 1 second for message 26: Message msg = _subscriber.Receive(TimeSpan.FromSeconds(1)); 27: if(msg != null) 28: { 29: OnMessageReceived(msg); 30: } 31: } 32: } 33: ... 34: } It seems so odd to write this kind of code now. Does it feel odd to you? Maybe it's just because I've gotten so used to delegation that I really don't like the feel of this. To me it is akin to saying that if I want to drive my car I need to derive a new instance of it just to put myself in the driver's seat. And yet, unquestionably, five years ago I would have probably written the code as you see above. To me, inheritance is a flawed approach for notifications due to several reasons: Inheritance is one of the HIGHEST forms of coupling. You can't seal the listener class because it depends on sub-classing to work. Because C# does not allow multiple-inheritance, I've spent my one inheritance implementing this class. Every time you need to listen to a bus, you have to derive a class which leads to lots of trivial sub-classes. The act of consuming a message should be a separate responsibility than the act of listening for a message (SRP). Inheritance is such a strong statement (this IS-A that) that it should only be used in building type hierarchies and not for overriding use-specific behaviors and notifications. Chances are, if a class needs to be inherited to be used, it most likely is not designed as well as it could be in today's modern programming languages. So lets look at the other tools available to us for getting notified instead. Here's a few other choices to consider. Have the listener expose a MessageReceived event. Have the listener accept a new IMessageHandler interface instance. Have the listener accept an Action<Message> delegate. Really, all of these are different forms of delegation. Now, .NET events are a bit heavier than the other types of delegates in terms of run-time execution, but they are a great way to allow others using your class to subscribe to your events: 1: // using event - ommiting argument null checks and halt logic 2: public sealed class MessageListener 3: { 4: private ISubscriber _subscriber; 5: private bool _isHalted = false; 6: private Thread _messageThread; 7:  8: // assign the subscriber and start the messaging loop 9: public MessageListener(ISubscriber subscriber) 10: { 11: _subscriber = subscriber; 12: _messageThread = new Thread(MessageLoop); 13: _messageThread.Start(); 14: } 15:  16: // user will override this to process their messages 17: public event Action<Message> MessageReceived; 18:  19: // handle the looping in the thread 20: private void MessageLoop() 21: { 22: while(!_isHalted) 23: { 24: // as long as processing, wait 1 second for message 25: Message msg = _subscriber.Receive(TimeSpan.FromSeconds(1)); 26: if(msg != null && MessageReceived != null) 27: { 28: MessageReceived(msg); 29: } 30: } 31: } 32: } Note, now we can seal the class to avoid changes and the user just needs to provide a message handling method: 1: theListener.MessageReceived += CustomReceiveMethod; However, personally I don't think events hold up as well in this case because events are largely optional. To me, what is the point of a listener if you create one with no event listeners? So in my mind, use events when handling the notification is optional. So how about the delegation via interface? I personally like this method quite a bit. Basically what it does is similar to inheritance method mentioned first, but better because it makes it easy to split the part of the class that doesn't change (the base listener behavior) from the part that does change (the user-specified action after receiving a message). So assuming we had an interface like: 1: public interface IMessageHandler 2: { 3: void OnMessageReceived(Message receivedMessage); 4: } Our listener would look like this: 1: // using delegation via interface - omitting argument null checks and halt logic 2: public sealed class MessageListener 3: { 4: private ISubscriber _subscriber; 5: private IMessageHandler _handler; 6: private bool _isHalted = false; 7: private Thread _messageThread; 8:  9: // assign the subscriber and start the messaging loop 10: public MessageListener(ISubscriber subscriber, IMessageHandler handler) 11: { 12: _subscriber = subscriber; 13: _handler = handler; 14: _messageThread = new Thread(MessageLoop); 15: _messageThread.Start(); 16: } 17:  18: // handle the looping in the thread 19: private void MessageLoop() 20: { 21: while(!_isHalted) 22: { 23: // as long as processing, wait 1 second for message 24: Message msg = _subscriber.Receive(TimeSpan.FromSeconds(1)); 25: if(msg != null) 26: { 27: _handler.OnMessageReceived(msg); 28: } 29: } 30: } 31: } And they would call it by creating a class that implements IMessageHandler and pass that instance into the constructor of the listener. I like that this alleviates the issues of inheritance and essentially forces you to provide a handler (as opposed to events) on construction. Well, this is good, but personally I think we could go one step further. While I like this better than events or inheritance, it still forces you to implement a specific method name. What if that name collides? Furthermore if you have lots of these you end up either with large classes inheriting multiple interfaces to implement one method, or lots of small classes. Also, if you had one class that wanted to manage messages from two different subscribers differently, it wouldn't be able to because the interface can't be overloaded. This brings me to using delegates directly. In general, every time I think about creating an interface for something, and if that interface contains only one method, I start thinking a delegate is a better approach. Now, that said delegates don't accomplish everything an interface can. Obviously having the interface allows you to refer to the classes that implement the interface which can be very handy. In this case, though, really all you want is a method to handle the messages. So let's look at a method delegate: 1: // using delegation via delegate - omitting argument null checks and halt logic 2: public sealed class MessageListener 3: { 4: private ISubscriber _subscriber; 5: private Action<Message> _handler; 6: private bool _isHalted = false; 7: private Thread _messageThread; 8:  9: // assign the subscriber and start the messaging loop 10: public MessageListener(ISubscriber subscriber, Action<Message> handler) 11: { 12: _subscriber = subscriber; 13: _handler = handler; 14: _messageThread = new Thread(MessageLoop); 15: _messageThread.Start(); 16: } 17:  18: // handle the looping in the thread 19: private void MessageLoop() 20: { 21: while(!_isHalted) 22: { 23: // as long as processing, wait 1 second for message 24: Message msg = _subscriber.Receive(TimeSpan.FromSeconds(1)); 25: if(msg != null) 26: { 27: _handler(msg); 28: } 29: } 30: } 31: } Here the MessageListener now takes an Action<Message>.  For those of you unfamiliar with the pre-defined delegate types in .NET, that is a method with the signature: void SomeMethodName(Message). The great thing about delegates is it gives you a lot of power. You could create an anonymous delegate, a lambda, or specify any other method as long as it satisfies the Action<Message> signature. This way, you don't need to define an arbitrary helper class or name the method a specific thing. Incidentally, we could combine both the interface and delegate approach to allow maximum flexibility. Doing this, the user could either pass in a delegate, or specify a delegate interface: 1: // using delegation - give users choice of interface or delegate 2: public sealed class MessageListener 3: { 4: private ISubscriber _subscriber; 5: private Action<Message> _handler; 6: private bool _isHalted = false; 7: private Thread _messageThread; 8:  9: // assign the subscriber and start the messaging loop 10: public MessageListener(ISubscriber subscriber, Action<Message> handler) 11: { 12: _subscriber = subscriber; 13: _handler = handler; 14: _messageThread = new Thread(MessageLoop); 15: _messageThread.Start(); 16: } 17:  18: // passes the interface method as a delegate using method group 19: public MessageListener(ISubscriber subscriber, IMessageHandler handler) 20: : this(subscriber, handler.OnMessageReceived) 21: { 22: } 23:  24: // handle the looping in the thread 25: private void MessageLoop() 26: { 27: while(!_isHalted) 28: { 29: // as long as processing, wait 1 second for message 30: Message msg = _subscriber.Receive(TimeSpan.FromSeconds(1)); 31: if(msg != null) 32: { 33: _handler(msg); 34: } 35: } 36: } 37: } } This is the method I tend to prefer because it allows the user of the class to choose which method works best for them. You may be curious about the actual performance of these different methods. 1: Enter iterations: 2: 1000000 3:  4: Inheritance took 4 ms. 5: Events took 7 ms. 6: Interface delegation took 4 ms. 7: Lambda delegate took 5 ms. Before you get too caught up in the numbers, however, keep in mind that this is performance over over 1,000,000 iterations. Since they are all < 10 ms which boils down to fractions of a micro-second per iteration so really any of them are a fine choice performance wise. As such, I think the choice of what to do really boils down to what you're trying to do. Here's my guidelines: Inheritance should be used only when defining a collection of related types with implementation specific behaviors, it should not be used as a hook for users to add their own functionality. Events should be used when subscription is optional or multi-cast is desired. Interface delegation should be used when you wish to refer to implementing classes by the interface type or if the type requires several methods to be implemented. Delegate method delegation should be used when you only need to provide one method and do not need to refer to implementers by the interface name.

    Read the article

  • Problem in calling a method recursively in nodejs mongodb [closed]

    - by Nilesh
    I am trying to create a tree using nodejs and mongodb.Wanted to show a path of a particulr node from the root.So I am finding the destination path and looping back to its parent iteratively until the root.So this is the snippet I am using which results in infinite looping articleProvider.finditsparent(t,function(error,tap){ if(tap[0].parent=='null') { t=(tap[0].parent); console.log(n); } else { n.push(tap[0].parent); console.log(tap[0].parent); t=(tap[0].parent); res.send(n); } }); res.send(n); }); How should I get rid of this problem?Is there any way to call it recursively?

    Read the article

  • Faulty memtest result

    - by dhojgaard
    I've been a bit suspicious about my RAM lately. They seem not work like i expect them to. For instance i run a lot of Virtual Test Environments in VMware Workstation and lately Ubuntu starts to lag just running 4 virtual machines each dedicated 512 MB. BTW im having 6GB memory on my laptop. This did not use to be a problem for me on my last laptop that even had a lot lower CPU resources. So i was led to try a memtest after reading some websites about RAM testing. So i did a memtest overnight but when i woke up this morning i was just looping and i could not Exit or do anything. It was just looping the number of errors besides test 7 which you can see in the lower right part of the screenshot. Can anyone interpret this screenshot for me? Do i have a faulty set of RAMs?

    Read the article

  • Loop OpenAL source with offset

    - by ressaw
    The OpenAL API states that an setting an offset still causes the sound to loop back to zero for looping sources. But is there a way to loop and still have an offset somehow? I have an mp3, and since it contains headers with information at the start of the file, there's a small, but noticable, delay in looping when it rewinds. If not, are there any other compressed formats that don't contain these empty headers?

    Read the article

  • Using FlashVars to pass variables to a SWF

    - by SoeTheingiLin
    I would like to pass over 50 items of variables from php to flash. Actually I want to pass array with foreach statement, looping through the array and assigning loop index to the variables and flash again accept the php values through looping. Is this possible? If passing values through foreach or loop statement is impossible, I would like to break a new line in tag. how can I break a new line in FlashVars tag?

    Read the article

  • How to delete multiple rows from datatable in VB.net 2008 ?

    - by KuldipMCA
    How to delete multiple rows from datatable in VB.net 2008 with out looping ? I do not want to delete from database. I want to delete from Local data table. I know the Select Method and also Remove and Remove at method too. but that needs looping to delete the ROWs from Datatable. I have 40000 Rows and i want to Delete selected 1000 Rows from that Datatable.

    Read the article

  • Silverlight Cream for January 30, 2011 - 2 -- #1038

    - by Dave Campbell
    In this Issue: Max Paulousky, Renuka Prasad, Ollie Riches, Jesse Liberty(-2-, -3-, -4-, -5-), Medusa M, John Papa, Beth Massi, and Joost van Schaik. Above the Fold: Silverlight: "Stop What You Are Doing And Learn About Reactive Programming" Jesse Liberty WP7: "Windows Phone Looping Selector for Digits " Max Paulousky Lightswitch: "How To Send HTML Email from a LightSwitch Application" Beth Massi Shoutouts: Shawn Wildermuch has niether GooNews for users of his cool WP7 app or or for the WP7 Marketplace in general: R.I.P. GooNews From SilverlightCream.com: Windows Phone Looping Selector for Digits Max Paulousky expanded on the Looping selector for some customization allowing him to display width/height metric measurement selectors... great job, Max! WP7 – How to Create a Simple Checked Listbox In Windows Phone 7 Renuka Prasad has the code for a nicely-working checked Listbox for WP7 on his blog... the post is the code... WP7Contrib: Network Connectivity Push Model Ollie Riches had a post last week that I'm just catching up to... about the 'push model' for network connectivity they produced in WP7 Contrib. Using the Camera in Windows Phone 7 Jesse Liberty has a bunch of posts up... I'm just going to bite the bullet and catch up! ... this 'From Scratch post 24 is all about the camera in your WP7 dev travails... and he makes it look so darned easy :) Linq and Fluent Programming Jesse Liberty's next post is 'From Scratch 25 and is all about Linq and Fluent Programming which started with a discussion at Codemash with Bill Wagner... wanna get a handle on fluent programming? ... check this out. Stop What You Are Doing And Learn About Reactive Programming Another item you might want to get your head around is Reactive Programming, or Rx... Jesse Liberty has a great post up discussing this, as his 'From Scratch post 26... good external links, and lots of commentary as well. Rx–Reactive Programming for Windows Phone Jesse Liberty's 'From Scratch 27 follows the previous on about Rx by taking the Rx show to the WP7 development arena. Want a solid Rx example... here ya go! Reactive Extensions–Observable Sequences are First Class Objects Finally catching up with Jesse Liberty (for now), I find this 'From Scratch number 28 which is again on Rx and WP7 dev, expanding on the example from the previous post by harnessing the power of Rx Localizing Silverlight applications Medusa M has a nice post up at dotnetslackers on localization in Silverlight. If you haven't had to do localization before, it can get to be a pain... understanding an article like this will get you part of the way to being pain-free. Silverlight TV 59: What Goes Into Baking Silverlight? Very cool presentation for those of you interested in the bits ... John Papa's Silverlight TV number 59 is up and he's chatting with Andy Rivas about the process followed getting the bits to us. How To Send HTML Email from a LightSwitch Application Beth Massi's latest Lightswitch post is on sending HTML Email via SMTP from Lightswitch, and then follows that up with sending Email via Outlook automation. ViewModel driven animations using the Visual State Manager, DataStateBehavior and Expression Blend After some good user feedback, Joost van Schaik decided to make some modifications to his WP7 app, and got involved in a Page Title collapse animation driven from the ViewModel. Check out the nice write-up, video, external links, and source... all good! Stay in the 'Light! Twitter SilverlightNews | Twitter WynApse | WynApse.com | Tagged Posts | SilverlightCream Join me @ SilverlightCream | Phoenix Silverlight User Group Technorati Tags: Silverlight    Silverlight 3    Silverlight 4    Windows Phone MIX10

    Read the article

  • MySQL Gurus: How to pull a complex grid of data from MySQL database with one query?

    - by iopener
    Hopefully this is less complex than I think. I have one table of companies, and another table of jobs, and a third table with that contains a single entry for each employee in each job from each company. NOTE: Some companies won't have employees in some jobs, and some companies will have more than one employee in some jobs. The company table has a companyid and companyname field, the job table has a jobid and jobtitle field, and the employee table has employeeid, companyid, jobid and employeename fields. I want to build a table like this: +-----------+-----------+-----------+ | Company A | Company B | Company C | ------+-----------+-----------+-----------+ Job A | Emp 1 | Emp 2 | | ------+-----------+-----------+-----------+ Job B | Emp 3 | | Emp 4 | | | | Emp 5 | ------+-----------+-----------+-----------+ Job C | | Emp 6 | | | | Emp 7 | | | | Emp 8 | | ------+-----------+-----------+-----------+ I had previously been looping through a result set of jobs, and for each job, looping through a result set of each company, and for each company, looping through each employee and printing it in a table (gross, but performance was not supposed to be a consideration). The app has grown in popularity, and now we have 100 companies and hundreds of jobs, and the server is crapping out (all the id fields are indexed). Any suggestions on how to write a single query to get this data? I don't need the company names or job titles (obviously), but I do need some way to identify where each row from the result should be printed. I'm imagining a result set that just contained a long list of joined employees, and I could write a loop to use the companyid and employeeid values to tell me when to create a new cell or table row. This works as long as there aren't ZERO employees; I would need a NULL employee name for that I think? Am I completely on the wrong track? Thanks in advance for any ideas!

    Read the article

  • Skipping the BufferedReader readLine() method in java

    - by DDP
    Is there a easy way to skip the readLine() method in java if it takes longer than, say, 2 seconds? Here's the context in which I'm asking this question: public void run() { boolean looping = true; while(looping) { for(int x = 0; x<clientList.size(); x++) { try { Comm s = clientList.get(x); String str = s.recieve(); // code that does something based on the string in the line above } // other stuff like catch methods } } } Comm is a class I wrote, and the receive method, which contains a BufferedReader called "in", is this: public String recieve() { try { if(active) return in.readLine(); } catch(Exception e) { System.out.println("Comm Error 2: "+e); } return ""; } I've noticed that the program stops and waits for the input stream to have something to read before continuing. Which is bad, because I need the program to keep looping (as it loops, it goes to all the other clients and asks for input). Is there a way to skip the readLine() process if there's nothing to read? I'm also pretty sure that I'm not explaining this well, so please ask me questions if I'm being confusing.

    Read the article

  • Getting MSExchange transport Error on Server 2003 SP2

    - by Scott
    I am getting the following Error messages and do not know how to fix it. Event Type: Error Event Source: MSExchangeTransport Event Category: (8) Event ID: 3017 Date: 4/29/2010 Time: 1:21:12 PM User: N/A Computer: NETSRV Description: A non-delivery report with a status code of 5.3.5 was generated for recipient rfc822;[email protected] (Message-ID <19104335.51321272561635734.JavaMail.SYSTEM@PARROT). Causes: A looping condition was detected. (The server is configured to route mail back to itself). If you have multiple SMTP Virtual Servers configured on your Exchange server, make sure they are defined by a unique incoming port and that the outgoing SMTP port configuration is valid to avoid looping between local virtual servers. Thanks for any help you can provide.

    Read the article

  • How to remove objects from an Enumerable collection in a loop

    - by johnc
    Duplicate Modifying A Collection While Iterating Through It Has anyone a nice pattern to allow me to get around the inability to remove objects while I loop through an enumerable collection (eg, an IList or KeyValuePairs in a dictionary) For example, the following fails, as it modifies the List being enumerated over during the foreach foreach (MyObject myObject in MyListOfMyObjects) { if (condition) MyListOfMyObjects.Remove(myObject); } In the past I have used two methods. I have replaced the foreach with a reversed for loop (so as not to change the any indexes I am looping over if I remove an object). I have also tried storing a new collection of objects to remove within to loop, then looping through that collection and removed the objects from the original collection. These work fine, but neither feels nice, and I was wondering if anyone has come up with a more elegant solution to the issue

    Read the article

  • Dealing with sequences in OpenCV?

    - by Farhad
    I have 2 sequences. One (lets call this cvSeq x), which contains a number of contours (derived from cvFindContours) and a second (lets call this cvSeq y) which I have used cvCreateSeq upon, but doesn't actually have anything in it. I am looping through all the contours in x, and if a contour meets specific criteria, I add it to y. I am able to do the looping, but I don't know how to add an contour in x to y if it meets the criteria. Does anyone know how to add a contour in a sequence to another sequence (that is empty)? Code examples will be appreciated. PS: cvStartFindContours is not an option.

    Read the article

  • Kill a 10 minute old zombie process in linux bash script

    - by Steve
    I've been tinkering with a regex answer by yukondude with little success. I'm trying to kill processes that are older than 10 minutes. I already know what the process IDs are. I'm looping over an array every 10 min to see if any lingering procs are around and need to be killed. Anybody have any quick thoughts on this? Thanks, Steve ps -eo uid,pid,etime 3233332 | egrep ' ([0-9]+-)?([0-9]{2}:?){3}' | awk '{print $2}' | xargs -I{} kill {} I've been tinkering with the answer posted by yukondude with little success. I'm trying to kill processes that are older than 10 minutes. I already know what the process IDs are. I'm looping over an array every 10 min to see if any lingering procs are around and need to be killed. Anybody have any quick thoughts on this? Thanks, Steve

    Read the article

  • Rationale behind Python's preferred for syntax

    - by susmits
    What is the rationale behind the advocated use of the for i in xrange(...)-style looping constructs in Python? For simple integer looping, the difference in overheads is substantial. I conducted a simple test using two pieces of code: File idiomatic.py: #!/usr/bin/env python M = 10000 N = 10000 if __name__ == "__main__": x, y = 0, 0 for x in xrange(N): for y in xrange(M): pass File cstyle.py: #!/usr/bin/env python M = 10000 N = 10000 if __name__ == "__main__": x, y = 0, 0 while x < N: while y < M: y += 1 x += 1 Profiling results were as follows: bash-3.1$ time python cstyle.py real 0m0.109s user 0m0.015s sys 0m0.000s bash-3.1$ time python idiomatic.py real 0m4.492s user 0m0.000s sys 0m0.031s I can understand why the Pythonic version is slower -- I imagine it has a lot to do with calling xrange N times, perhaps this could be eliminated if there was a way to rewind a generator. However, with this deal of difference in execution time, why would one prefer to use the Pythonic version?

    Read the article

  • Speech Recognition Server Does Not Stay Open

    - by Waffle
    I am trying to create a simple program that loops for user speech input using com.apple.speech.recognitionserver. My code thus far is as follows: set user_response to "start" repeat while user_response is not equal to "Exit" tell application id "com.apple.speech.recognitionserver" set user_response to listen for {"Time", "Weather", "Exit"} with prompt "Good Morning" end tell if user_response = "Time" then set curr_time to time string of (the current date) set curr_day to weekday of (the current date) say "It is" say curr_time say "on" say curr_day say "day" else if user_response = "Weather" then say "It is hot outside. What do you expect?" end if end repeat say "Have a good day" If the above is run on my system it says good morning and it then pops up with the speech input system and waits for either Time, Weather, or Exit. They all do what they say they are going to do, but instead of looping if I say Time and Weather and asking again until I say exit the speechserver times out and never pops up again. Is there a way of either keeping that application open until the program ends or is applescript not capable of looping for user speech input?

    Read the article

  • Checking if an int is prime more efficiently

    - by SipSop
    I recently was part of a small java programming competition at my school. My partner and I have just finished our first pure oop class and most of the questions were out of our league so we settled on this one (and I am paraphrasing somewhat): "given an input integer n return the next int that is prime and its reverse is also prime for example if n = 18 your program should print 31" because 31 and 13 are both prime. Your .class file would then have a test case of all the possible numbers from 1-2,000,000,000 passed to it and it had to return the correct answer within 10 seconds to be considered valid. We found a solution but with larger test cases it would take longer than 10 seconds. I am fairly certain there is a way to move the range of looping from n,..2,000,000,000 down as the likely hood of needing to loop that far when n is a low number is small, but either way we broke the loop when a number is prime under both conditions is found. At first we were looping from 2,..n no matter how large it was then i remembered the rule about only looping to the square root of n. Any suggestions on how to make my program more efficient? I have had no classes dealing with complexity analysis of algorithms. Here is our attempt. public class P3 { public static void main(String[] args){ long loop = 2000000000; long n = Integer.parseInt(args[0]); for(long i = n; i<loop; i++) { String s = i +""; String r = ""; for(int j = s.length()-1; j>=0; j--) r = r + s.charAt(j); if(prime(i) && prime(Long.parseLong(r))) { System.out.println(i); break; } } System.out.println("#"); } public static boolean prime(long p){ for(int i = 2; i<(int)Math.sqrt(p); i++) { if(p%i==0) return false; } return true; } } ps sorry if i did the formatting for code wrong this is my first time posting here. Also the output had to have a '#' after each line thats what the line after the loop is about Thanks for any help you guys offer!!!

    Read the article

  • C#: Efficiently search a large string for occurences of other strings

    - by Jon
    Hi, I'm using C# to continuously search for multiple string "keywords" within large strings, which are = 4kb. This code is constantly looping, and sleeps aren't cutting down CPU usage enough while maintaining a reasonable speed. The bog-down is the keyword matching method. I've found a few possibilities, and all of them give similar efficiency. 1) http://tomasp.net/articles/ahocorasick.aspx -I do not have enough keywords for this to be the most efficient algorithm. 2) Regex. Using an instance level, compiled regex. -Provides more functionality than I require, and not quite enough efficiency. 3) String.IndexOf. -I would need to do a "smart" version of this for it provide enough efficiency. Looping through each keyword and calling IndexOf doesn't cut it. Does anyone know of any algorithms or methods that I can use to attain my goal?

    Read the article

  • Windows Service suddenly doing nothing

    - by TB
    Hi, My windows service is using a Thread (not a timer) which is always looping and sleeps for 1 second every loop using : evet.WaitOne(interval); When I start the service it works fine and I can see in the task manager that it is running, consuming and releasing memory, consuming processor ... etc that is all normal, but after a while (random amount of time) the service simply stops!! it is still there in the task manager but it is not consuming any processor work now and its consumption to the memory is not changing. it simply (died but still there in the task manager like a Zombie). I know that many exceptions might have happened during running the service (it is really doing many things) but all those exceptions are handled in Try catch blocks, so why is my "always looping" thread stops ??? This thread also logs every time he loops, when he is freezig in this way he is not logging anything (of course)

    Read the article

  • Array basics - Populating with loop

    - by madlan
    Hi, I'm looping through a zip file trying to add the file name of each file within. Is this the correct method? Dim ZipNameArray(?) Using zip As ZipFile = ZipFile.Read(ZipToUnpack) For Each file In zip ZipNameArray(?) = file .FileName Next End Using I do not know the array size until I start looping through the zip (To work out the number of files within). How do I increment the Array? file is not a number? (It's a ZipEntry)

    Read the article

< Previous Page | 5 6 7 8 9 10 11 12 13 14 15 16  | Next Page >