Skip to main content

Posts

Showing posts with the label Thread

How to stop a blocking thread from another function that start in other in MFC

ISSUE: In server client scenario it is mandatory to use thread where sever is listening on a particular port. Now in click of stop button ,how to stop this running thread. SOLUTION: #include <Windows.h> HANDLE m_Thread_handle; CWinThread *cTh; static UINT __cdecl StaticThreadFunc(LPVOID pParam); UINT ThreadFunc(); Step 1. Declared these on header file. Step 2. Starting the thread from a function or button click --- void CServerDlg::OnBnClickedStart() {     // TODO: Add your control notification handler code here     cTh = AfxBeginThread(     StaticThreadFunc,     this);     m_Thread_handle = cTh->m_hThread; } Step 3. Thread initialization function --  UINT __cdecl CServerDlg::StaticThreadFunc(LPVOID pParam) {     CServerDlg *pYourClass = reinterpret_cast<CServerDlg*>(pParam);     UINT retCode = pYourClass->ThreadFunc();   ...

Best design for windows multi thread in a c++ class

ISSUE: How to create windows multi-threaded program in  c++ ? SOLUTION:   Now a day maximum project or software has multiple process running at a same process.Or a gui application needs to do some work on background which is blocking. Or may be you are going to design or create a network application ,so it becomes mandatory to be an expert of Threading now a days. Here is  the template which I follow. In header file add the followings -- #include <Windows.h> static UINT __cdecl CallingFunctionForThread ( LPVOID pParam ); UINT WorkingFunction ();   In CPP file add the followings -- UINT __cdecl My Class :: CallingFunctionForThread ( LPVOID pParam ) { My Class * pMy Class = reinterpret_cast < My Class *>( pParam ); UINT ret = pMy Class -> WorkingFunction (); return ret ; } UINT My Class :: WorkingFunction () { // You can do anything as a class member function and run it on your thread. } Start ...

Web Crawler or Site grabber code in java with Page downloader

/**  * @Web Crawler *  *  * @author sharma  * @version 1.00 2010/7/16  */ import java.io.BufferedInputStream; import java.io.IOException; import java.net.MalformedURLException; import java.util.*; import java.net.URLConnection; import java.awt.BorderLayout; import java.awt.Color; import javax.swing.JFrame; import javax.swing.JTabbedPane; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JButton; import javax.swing.SwingConstants; import javax.swing.*; import java.awt.*; import java.awt.event.*; import java.awt.Transparency; import javax.swing.event.*; import java.sql.*; import java.util.*; import java.net.URL; import javax.imageio.ImageIO; import java.lang.*; import java.io.*; import javax.swing.BoxLayout; public class assign_3 extends JFrame {        String name="";     String str[] = new String[1000];     int k;     StringBui...