background-thread

How to execute a method every second on a background thread so it doesn't affect the performance of the app

帅比萌擦擦* 提交于 2020-02-05 04:25:09
问题 I am trying to access my database every 30 seconds, however, whenever the method executes I can clearly see a performance dip in the application. So far this is my current code: var timer = Timer() override func viewDidLoad() { super.viewDidLoad() scheduledTimerWithTimeInterval() } func scheduledTimerWithTimeInterval(){ timer = Timer.scheduledTimer(timeInterval: 30, target: self, selector: #selector(self.updateCounting), userInfo: nil, repeats: true) } @objc func updateCounting(){

upload files in background via ftp on iphone

☆樱花仙子☆ 提交于 2020-01-14 04:43:11
问题 i'm trying to establish an FTP connection within an app. i want to upload several files to a FTP server, all files in one directory. So at first i want to create the remote directory. - (void) createRemoteDir { NSURL *destinationDirURL = [NSURL URLWithString: uploadDir]; CFWriteStreamRef writeStreamRef = CFWriteStreamCreateWithFTPURL(NULL, (__bridge CFURLRef) destinationDirURL); assert(writeStreamRef != NULL); ftpStream = (__bridge_transfer NSOutputStream *) writeStreamRef; BOOL success =

Speed up the response retriever from server in iphone

雨燕双飞 提交于 2020-01-06 08:10:59
问题 I am using following code to get results from server NSString *queryString = @"MyString" NSString *response = [NSString stringWithContentsOfURL:[NSURL URLWithString:queryString] encoding:NSUTF8StringEncoding error:&err]; NSLog(@"%@",response); if (err != nil) { UIAlertView *alert = [[UIAlertView alloc]initWithTitle: @"Error" message: @"An error has occurred. Kindly check your internet connection" delegate: self cancelButtonTitle:@"Ok" otherButtonTitles:nil]; [alert show]; [indicator

NullPointerException in HandlerThread

十年热恋 提交于 2020-01-01 12:05:13
问题 This bug baffled me for hours. I am getting the NullPointerException . The problem is this error is not consistent. It happens when I launch the app, but only occasionally. So I am not sure what is causing it. I apologize for the verbose question with the error log, but I could not find another way of asking. The error log is as follows: FATAL EXCEPTION: main Process: com.myproject.android, PID: 22175 java.lang.NullPointerException at com.myproject.android.ImageDownloaderThread.queueImage

NullPointerException in HandlerThread

故事扮演 提交于 2020-01-01 12:04:32
问题 This bug baffled me for hours. I am getting the NullPointerException . The problem is this error is not consistent. It happens when I launch the app, but only occasionally. So I am not sure what is causing it. I apologize for the verbose question with the error log, but I could not find another way of asking. The error log is as follows: FATAL EXCEPTION: main Process: com.myproject.android, PID: 22175 java.lang.NullPointerException at com.myproject.android.ImageDownloaderThread.queueImage

Updating Views from non-UI threads

一笑奈何 提交于 2019-12-30 04:59:07
问题 I am confused about how the Android system works, specially when it updates the view hierarchy. We all know that we should not update any view from any thread other than UI (Main) thread . And even Android system throws exception when we try to do so. The other day I was trying to implement a custom progress showing view in my application. So I started with using standard Java threads and handler combo. What I found surprised me as I was able to update a TextView from background thread. new

What happens if I run an Android thread in the background indefinitely

自闭症网瘾萝莉.ら 提交于 2019-12-24 08:04:46
问题 Android docs indicate that Oreo has new restrictions on background execution: https://developer.android.com/about/versions/oreo/background. This seems reasonable and they're clearly aiming to make their platform more like iOS and prevent apps running rampant in the background. The thing that's unclear to me (in fact, not documented at all) is what can you do on a thread when the UI goes to the background. Specifically, GIVEN I create a thread with new Thread(() -> { // Naughty thread doing

ASP.NET Background thread Performance Guidance

不想你离开。 提交于 2019-12-23 02:35:05
问题 I am running a background thread in my asp.net web service application. This thread's responsibility is to hit database after a specific time and update a datatable in the Cache. The data table has around 500K rows. In task manager when I look in processes, the web dev server for first time consumes around 300,000K on next time it goes to 500,000K and some times it reaches above 1,000,000K and sometimes drop back to 500,000-600,000K. As I am doing work on my local machine so data in database

MFC C++ Background Thread

老子叫甜甜 提交于 2019-12-20 04:33:15
问题 I am making an MFC (document/view) application and I want it to constantly listen in the background for when a device is connected and then automatically copy the files on the device without the user needing to interact or pause/disturb what they are doing. Is creating a worker thread the same as having a background thread? Would I create it as a function in the document file or as a separate class? Thanks, 回答1: Yes, they behave as a normal background threads, you have a function that gets

How to run certain task every day at a particular time using ScheduledExecutorService?

自闭症网瘾萝莉.ら 提交于 2019-12-17 02:34:10
问题 I am trying to run a certain task everyday at 5 AM in the morning. So I decided to use ScheduledExecutorService for this but so far I have seen examples which shows how to run task every few minutes. And I am not able to find any example which shows how to run a task every day at a particular time (5 AM) in the morning and also considering the fact of daylight saving time as well - Below is my code which will run every 15 minutes - public class ScheduledTaskExample { private final